SNag
SNag

Reputation: 18151

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!

Upvotes: 0

Views: 11748

Answers (2)

guido.rota
guido.rota

Reputation: 104

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)

Upvotes: 1

Jai Govindani
Jai Govindani

Reputation: 3211

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.

Upvotes: 0

Related Questions