[英]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. 在我目前正在从事的BI项目中,我们需要地理位置坐标以获取位置列表。 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}
). 使用地址位置(例如
"New York, US"
)作为输入,输出应该是经纬度对(例如{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. 关于SO的类似问题也指向在JavaScript中使用Google Maps API来实现此目的,但我正在寻找Java解决方案
getCoordinates(location)
形式的某些功能,因为这在较大的Java中是一个很小的要求程序已经存在。
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! 任何有关如何在Java中使用Google Maps API(或任何其他maps API)来实现此目标的指示都将大有帮助!
You can use the Google Geocoding HTTP API (see here ). 您可以使用Google Geocoding HTTP API(请参阅此处 )。 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)
要连接到它并获取响应,您可以使用Java URLConnection(教程在此处 ),并使用您喜欢的Json库解析响应(我个人使用Jackson)
So you'd like a way to perform Google Maps API Geocoding via Java - here's one that might work for you. 因此,您想要一种通过Java执行Google Maps API地理编码的方法-这可能对您有用。 The response might not be in the exact same format you need but should be pretty workable:
响应的格式可能与您所需的格式不完全相同,但是应该可以使用:
http://code.google.com/p/geocoder-java/ 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. 您可以看到LatLng.java中返回的最终格式-只需从GeocodeResponse.java开始跟踪代码,您将看到最终格式-这些类非常简单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.