简体   繁体   中英

How do I use Google Maps API in a Java code to fetch coordinates of specified location?

In a BI project I'm currently working on, we are in need of geo-coordinates for a list of locations. With the address location (such as "New York, US" ) as input, the output should be the coordinates as a latitude-longitude pair (like {40.71435, -74.00597} ). The behaviour is similar to what is seen on this page.

A similar question earlier on SO points to using the Google Maps API in JavaScript to achieve this, but I'm looking for a Java solution -- some function of the form getCoordinates(location) , because this is a small requirement in a larger Java program already in existence.

Any pointers on how I may use the Google Maps API (or any other maps API) in Java to achieve this would be of great help!

You can use the Google Geocoding HTTP API (see here ). To connect to it and get the responses you can use a Java URLConnection (tutorial is here ) and parse the response using your favourite Json library (I personally use Jackson)

So you'd like a way to perform Google Maps API Geocoding via Java - here's one that might work for you. The response might not be in the exact same format you need but should be pretty workable:

http://code.google.com/p/geocoder-java/

You can see the final format returned in LatLng.java - just trace the code through starting from GeocodeResponse.java and you'll see the final format - the classes are pretty simple.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM