Google Place API获取纬度和广度经度的地方

时间:2016-07-11 11:09:46

标签: android autocomplete google-places-api

我如何获得纬度&来自 Google Place API of android 的经度?我的代码如下所示..

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

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

我在获得超过 5个结果的结果时也遇到了问题。我正在使用this链接作为参考。任何帮助都会很感激。

1 个答案:

答案 0 :(得分:4)

你应该做那样的事情:

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();
  }
});