将PlaceID字符串转换为LatLng对象

时间:2019-01-16 09:25:15

标签: android google-maps google-places-api

我试图将我存储在数据库中的placeId字符串转换为LatLng坐标,所以我得到的ID像这样:place.getId()来自一个位置对象,现在当我从服务器取回它时,我想进行转换它返回到坐标或至少一个Place对象。

谢谢!

1 个答案:

答案 0 :(得分:1)

将对象声明为

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复制的代码)

相关问题