Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Need help to connect Google api

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Need help to connect Google api

    Hello,


    I am new to Java programming. I want to connect to google api

    I want to pass address and sensor, two parameters and get the xml or json output from api . Can anyone help me with this coding? your help is much appreciated. Thanks!!


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Need help to connect Google api

    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Oct 2013
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need help to connect Google api

    Quote Originally Posted by Norm View Post

    I have used below code to access google api.



    public class TestConn {
    public static void main(String args [])
    {
    try{
    URL hp = new URL("http://maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+Vi ew,+CA&sensor=true_or_false");
    HttpsURLConnection hpCon = (HttpsURLConnection)hp.openConnection();

    boolean isProxy = hpCon.usingProxy();
    System.out.println("is using proxy " + isProxy);
    InputStream obj = (InputStream) hpCon.getInputStream();
    while(obj.read()!=-1){
    System.out.println(obj.read_char());

    }
    System.out.println("content >> " + obj.toString());
    }catch (Exception ex){
    ex.printStackTrace();
    }
    }

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Need help to connect Google api

    Please copy the full text of any error messages and paste it here.

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  5. The Following User Says Thank You to Norm For This Useful Post:

    ashish_bakhale (October 5th, 2013)

  6. #5
    Junior Member
    Join Date
    Oct 2013
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need help to connect Google api

    try {
    URL oracle = new URL("http://maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+Vi ew,+CA&sensor=true");
    BufferedReader in = new BufferedReader(
    new InputStreamReader(oracle.openStream()));
    StringBuilder responseBuilder= new StringBuilder();

    String inputLine;
    while ((inputLine = in.readLine()) != null)
    {
    responseBuilder.append(inputLine + '\n');
    }
    NEWFIELD= inputLine;
    generateRow();
    in.close();

    }catch (Exception ex){
    ex.printStackTrace();
    }



    I went through some material and was able to develop above code.
    with this code i am able to read the last line of Google api xml output.


    Can anyone guide me providing suggestion to on to read the entire xml (from http://maps.googleapis.com/maps/api/...CA&sensor=true) and same it in NEWFIELD??

  7. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Need help to connect Google api

    i am able to read the last line of Google api xml output.
    The code saves all of the response it receives in the responseBuilder StringBuilder object. You need to extract it from there into a String.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. How to Send emails from Google Mail using JavaMail API
    By JavaPF in forum Java SE API Tutorials
    Replies: 3
    Last Post: February 26th, 2012, 04:21 PM
  2. Using Google Calendar API
    By anis_huq in forum Android Development
    Replies: 0
    Last Post: February 11th, 2012, 02:00 PM
  3. [SOLVED] Google translate API
    By vozmen in forum Java ME (Mobile Edition)
    Replies: 8
    Last Post: December 14th, 2011, 07:06 AM
  4. [SOLVED] Google translate api
    By vozmen in forum Java ME (Mobile Edition)
    Replies: 2
    Last Post: December 14th, 2011, 05:02 AM
  5. How to Send emails from Google Mail using JavaMail API
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 1
    Last Post: November 14th, 2010, 11:00 AM