Google Place API获取地点的纬度和经度

我如何从 Google Place API of android 获得 latitude & longitude ?我的代码如下所示..

AutocompleteFilter mAutocompleteFilter = new AutocompleteFilter.Builder().setTypeFilter(AutocompleteFilter.TYPE_FILTER_CITIES).build();

PendingResult<AutocompletePredictionBuffer> results =
                    Places.GeoDataApi
                            .getAutocompletePredictions(mGoogleApiClient, constraint.toString(),
                                    mBounds, mAutocompleteFilter);

我也很难获得超过 5 results 的结果 . 我正在使用this链接作为参考 . 任何帮助将不胜感激 .

回答(1)

2 years ago

你应该这样做:

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

  @Override
  public void onResult(PlaceBuffer p) {
    if (p.getStatus().isSuccess()) {
      final Place mPlace = p.get(0);
      LatLng qLoc = mPlace.getLatLng();
      //you can use lat with qLoc.latitude;
      //and long with qLoc.longitude;
    }
    p.release();
  }
});