代码之家  ›  专栏  ›  技术社区  ›  Arel Sharon

将placeID字符串转换为latlng对象

  •  1
  • Arel Sharon  · 技术社区  · 7 年前

    我试图将存储在数据库中的placeID字符串转换为latlng坐标,得到的ID如下: place.getId() 从一个Place对象,现在当我从服务器中注销它时,我想把它转换回坐标或者至少是一个Place对象。

    谢谢您!

    1 回复  |  直到 7 年前
        1
  •  1
  •   Marco    7 年前

    将对象声明为

    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 )