gpt4 book ai didi

android - 如何在 Android 中从名称或经纬度获取 PlaceID?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:59:36 26 4
gpt4 key购买 nike

这是我的代码:

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() 这样的东西。

也许我使用另一个 API 从上面的代码中从名称或纬度获取 PlaceID。谢谢!

最佳答案

看看这个docs .您将获得 Address 的纬度、经度和名称然后在 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"
}

在那里您将获得地点 ID。

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 - 如何在 Android 中从名称或经纬度获取 PlaceID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34283484/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com