android - 将 PlaceID 字符串转换为 LatLng 对象

标签 android google-maps google-places-api

我试图将我存储在数据库中的 placeId 字符串转换为 LatLng 坐标,我得到了这样的 id:place.getId() 从一个地方对象,现在当我从我想将其转换回坐标或至少一个 Place 对象的服务器。

谢谢!

最佳答案

声明对象为

GoogleApiClient mGoogleApiClient;

然后初始化为

 mGoogleApiClient =
            new GoogleApiClient.Builder(...)
            ...
            .build();

并将其传递给 Places API 的函数。

Places.GeoDataApi.getPlaceById(mGoogleApiClient, placeId)
.setResultCallback(new ResultCallback<PlaceBuffer>() {

@Override
  public void onResult(PlaceBuffer places) {
    if (places.getStatus().isSuccess()) {
      final Place myPlace = places.get(0);
      LatLng queriedLocation = myPlace.getLatLng();
      Log.v("Latitude is", "" + queriedLocation.latitude);
      Log.v("Longitude is", "" + queriedLocation.longitude);
    }
    places.release();
  }
});

并在回调中检索坐标。 (代码从 here 复制)

关于android - 将 PlaceID 字符串转换为 LatLng 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54213872/

相关文章:

android - 操作系统终止我的 Activity 后,SlidingUpPanelLayout 不会在恢复时崩溃

java - AsyncTask 中 ProgressDialog 的 NullPointerException

jquery - 可拖动变为可拖动

android - 如何自定义snackBar 的布局?

javascript - 减少 Google 地方信息自动完成请求的数量

javascript - 谷歌地图可以有透明背景吗?

javascript - 从 Google Places API 响应获取地址组件的最佳方式

google-maps - 如何在谷歌地图上获取平均交通数据

google-maps - 我可以将 Google Places API 中的姓名、地址和纬度/经度存储在我自己的数据库中吗

android - IllegalStateException:无法执行 Activity 的方法