我有一个地址列表,我现在要检索它们的经度和纬度。我想通过java使用谷歌地图api。我将如何去检索一个地址的一组合作伙伴。 (因为我可以那么轻松实现多)从谷歌地图api取得坐标
0
A
回答
3
这是怎么我到底
public static String getCordinates(String address,String county) throws IOException, ParserConfigurationException, SAXException{
String thisLine;
address = address.replace(",", "+");
address = address.replace(" ", "+");
county = county.replace(" ", "");
String fullAddress = address+"+"+county;
System.out.println(fullAddress);
URL url = new URL("http://maps.google.com/maps/geo?q="+fullAddress+"&output=xml&key=ABQIAAAANGTAqDyDam_07aWkklK2NBSD41w" +
"X8VhCBpuiDVjGbFNuXE31lhQB8Gkwy-wmYbmaHIbJtfnlR9I_9A");
BufferedReader theHTML = new BufferedReader(new InputStreamReader(url.openStream()));
FileWriter fstream = new FileWriter("url.xml");
BufferedWriter out = new BufferedWriter(fstream);
while ((thisLine = theHTML.readLine()) != null)
out.write(thisLine);
out.close();
File file = new File("url.xml");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file);
doc.getDocumentElement().normalize();
NodeList nl = doc.getElementsByTagName("code");
Element n = (Element)nl.item(0);
String st = n.getFirstChild().getNodeValue();
if (st.equals("200"))
{
NodeList n2 = doc.getElementsByTagName("coordinates");
Element nn = (Element)n2.item(0);
String st1 = nn.getFirstChild().getNodeValue();
return st1;
}
else
{
return null;
}
}
2
您可以使用此Google API
+0
我将如何去在java中调用这个,或者有没有在java中使用这个例子? – molleman 2011-06-04 10:14:40
+0
你需要从java发出http请求。只需谷歌功能。 – 2011-06-04 10:37:00
5
您也可以使用谷歌地理编码的Java API GeoGoogle喜欢做的这样的:
// Initialize a new GeoAddressStandardizer-class with your API-Key
GeoAddressStandardizer st = new GeoAddressStandardizer(apikey);
// Get a list of possible matching addresses
List<GeoAddress> addresses = st.standardizeToGeoAddresses(address);
// Get the first address (like you posted above)
GeoAddress address = addresses.get(0);
// Get the coordinates for the address
GeoCoordinate coords = address.getCoordinate();
// Longitude
double longitude = coords.getLongitude();
// Latitude
double latitude = coords.getLatitude();
0
使用API与restAssurd是一个简单的方法:
public static String[] getCoordinates(String address, String county) throws IOException, ParserConfigurationException, SAXException {
address = address.replace(",", "+");
address = address.replace(" ", "+");
county = county.replace(" ", "");
String fullAddress = address+"+"+county;
System.out.println(fullAddress);
URL url = new URL("http://maps.google.com/maps/api/geocode/json?address="+fullAddress+"&sensor=false");
Response res = given().
when().
get(url);
JsonPath jp = new JsonPath(res.asString());
String lat = jp.get("results.geometry.location.lat").toString();
String lng = jp.get("results.geometry.location.lng").toString();
String[] location = new String[2];
location[0] = lat;
location[1] = lng;
return location;
}
相关问题
- 1. 从谷歌地图中的地区名称获取坐标Api
- 2. 谷歌地球api获取坐标
- 3. 谷歌地图API定位角坐标
- 4. 使用谷歌地图获取地图角坐标 - javascript api
- 5. Android谷歌地图坐标
- 6. Android:谷歌地图坐标
- 7. Android谷歌地图坐标
- 8. 谷歌地图坐标圈
- 9. 如何从谷歌地图获取地址和坐标
- 10. 从谷歌地图获取地址和坐标
- 11. 谷歌地图api v2获取多边形坐标
- 12. 从嵌入谷歌地图中提取标记坐标
- 13. 寻找脚本,从谷歌地图获得坐标
- 14. 如何获得价值从谷歌地图坐标API性反应
- 15. 谷歌Places API所获取的坐标
- 16. 谷歌地图API标记
- 17. 谷歌地图 - 提取地图中心的坐标?
- 18. iPhone SDK:从谷歌地图获取GPS坐标
- 19. 获取GPS坐标编程方式从谷歌地图
- 20. 得到谷歌从JSON坐标映射
- 21. 从谷歌地图获取评论api
- 22. 谷歌地图的隐藏坐标
- 23. 使用谷歌地图使用坐标
- 24. 谷歌地图操作Lat/Lng坐标
- 25. 谷歌地图:找出坐标
- 26. 谷歌地图上的GPS坐标
- 27. 如何使用谷歌地图JavaScript API v3获取谷歌地图中查看区域中心的坐标
- 28. 获取坐标上的鼠标点击谷歌地图api v3和angularJS
- 29. 在Android Studio中传递UTM坐标与谷歌地图API
- 30. 谷歌地图JavaScript API v3的GPS坐标为中心
你想知道这个API吗? – 2011-06-04 09:57:58
我想知道如何检索从特定地址的api调用返回的json文件中的协调器..我也想知道如何请求json文件本身..所有从java – molleman 2011-06-04 10:07:15
你可以通过我在我的答案中提到的链接。你可以得到所有的细节。 – 2011-06-04 10:08:34