Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在安卓系统中,如何从name(或lat)long中获取PlaceID?_Android_Google Geocoder - Fatal编程技术网

Android 在安卓系统中,如何从name(或lat)long中获取PlaceID?

Android 在安卓系统中,如何从name(或lat)long中获取PlaceID?,android,google-geocoder,Android,Google Geocoder,这是我的代码: 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

这是我的代码:

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();
            }
        }
Geocoder-Geocoder=new-Geocoder(这个,Locale.getDefault());
列表地址=geocoder.getFromLocationName(文本,10);
test.clear();
对于(int i=0;i地址的lat,long名称
然后在GoogleAPI下面调用它

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"
}
在那里,您将获得place-id

注意:请从启用地理位置Api,否则返回错误消息:此Api项目无权使用此Api


您还可以使用直接搜索代替近距离搜索
https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&key=您的API密钥


看看

这两种提议都需要花钱,我认为人们应该提及。我们从谷歌那里得到了-200美元,但这一切都取决于你有多少用户以及你需要使用地理编码的频率。每个月向地理编码者提出60k个请求-仅使用地理编码https API就可以轻松获得300美元:

2018年11月1日至30日 地理编码API地理编码:6073个计数-$30.38

不要像我们在其他帖子的请求中所做的那样,在回复中过滤你需要的内容?期待更多:

2018年11月1日至30日 地点API地点详细信息:2389计算$40.61

2018年11月1日至30日 Places API联系人数据:2385计7.17美元

2018年11月1日至30日
Places API大气数据:2385计算$11.95

我建议使用这样的获取地点Id。这比直接调用API要好。 我一整天都在为这个问题纠结。所以我希望这会有所帮助。谁正在寻找从您当前位置获取位置ID的方法。 对于android

科特林

val-mPlaceDetectionClient=Places.getPlaceDetectionClient(this.context!!)
val placeResult=mPlaceDetectionClient.getCurrentPlace(null)
placeResult.addOnCompleteListener(对象:OnCompleteListener{
覆盖未完成的乐趣(p0:任务){
val-likelyPlaces=p0.01结果
if(可能是places.any()){
//从下面的代码中获取位置ID
placeId=likelyPlaces[0]。place.id}
}
})
或者,如果谁正在另一种语言(如java)上实现或开发,您可以根据下面的参考来实现您的代码

java


他们的服务条款限制在客户端应用程序(如android应用程序)中使用此功能。您需要在服务器上运行此应用程序并将其缓存。这是web api,而不是android api,OP希望通过官方android实现此功能sdk@JohnLeehey那么,我们如何从客户端设备上的lat/lng获取位置信息呢mEndre@KhalilKhalaf你需要在谷歌注册一个账单账户。然后,
你的API密钥
将替换为该google帐户提供给您的帐户,并将根据您提出的请求量为您计费。这是地理编码api而不是place api,因此响应中将不包含place id这不起作用,它说我未经授权?