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!!
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.
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!!
If you don't understand my answer, don't ignore it, ask a question.
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();
}
}
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.
ashish_bakhale (October 5th, 2013)
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??
The code saves all of the response it receives in the responseBuilder StringBuilder object. You need to extract it from there into a String.i am able to read the last line of Google api xml output.
If you don't understand my answer, don't ignore it, ask a question.