将 PlaceID 字符串转换为 LatLng 对象



我试图将存储在数据库中的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();
  }
});

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

最新更新