简体   繁体   English

如何在Java代码中使用Google Maps API来获取指定位置的坐标?

[英]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.

相关问题 如何在Android上使用Google Maps Directions API? - How do I use Google Maps Directions API on Android? 如何在Java中使用Google Calendar API? - How do I use the Google Calendar API with Java? 如何在Google Calendar Java API中使用FreeBusyResponse? - How do I use the FreeBusyResponse in Google Calendar java API? 如何获取Google Maps“Places API”以返回邮政编码信息? - How do I get Google Maps “Places API” to return ZIP code information? Android应用程式,Google Maps Java的api位置验证 - Android app, Google maps api location validation for java 如何在Google Elevation API中使用坐标数组? - How to use an array of coordinates with Google Elevation API? 如何在Java Google Maps中更改群集对象的图标 - How do I change the icons for the cluster objects in java google maps 我如何通过java代码将单个文件上传到指定项目的指定分支,因为没有合适的api接口 - how can i upload a single file to specified branch of specified project by java code , as there is no suitable api interface 如何在Java Application中访问google maps api? - How to access google maps api in Java Application? Google地图如何快速找到我的位置,但是当我使用位置管理器时,我需要等待40秒以上 - How does Google maps find my location quickly but when I use Location Manager I need to wait 40+seconds
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM