如何在Android中长时间从名称或经纬度获取PlaceID? [英] How to get PlaceID from name, or lat, long in Android?
本文介绍了如何在Android中长时间从名称或经纬度获取PlaceID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocationName(text, 10);
test.clear();
for (int i = 0; i < addresses.size(); i++) {
Address address = addresses.get(i);
for (int j=0;j<address.getMaxAddressLineIndex();j++) {
test.add(address.getAddressLine(j) + ", " + address.getCountryName());
// address.getLatitude();
// address.getLatitude();
}
}
但是我找不到诸如address.getPlaceID()之类的东西.
But I can't find something like address.getPlaceID().
也许我使用另一个API从上面的代码中从name或lat中获取PlaceID.谢谢!
Maybe I use another API get PlaceID from name, or lat, long from above code. Thanks!
推荐答案
查看此文档一个>.
您将获得Address
的纬度,经度,名称
然后在google api下面称呼它
Look at this docs.
You will get the lat,long,name for the Address
and then call this below google api
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&types=food&name=cruise&key=YOUR_API_KEY
您将收到这样的回复
{
"html_attributions" : [],
"results" : [
{
"geometry" : {
"location" : {
"lat" : -33.870775,
"lng" : 151.199025
}
},
...
"place_id" : "ChIJrTLr-GyuEmsRBfy61i59si0",
...
}
],
"status" : "OK"
}
在那里,您将获得地方编号.
For there you will get the place-id.
注意:请从 Google Developer Console 启用GeoLocation Api,否则将返回错误msg:此API项目无权使用此API.
Note: Please enable the GeoLocation Api from Google Developer Console otherwise it return the error msg :This API project is not authorized to use this API.
这篇关于如何在Android中长时间从名称或经纬度获取PlaceID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文