get Lat Lang from a place_id returned by autocomplete place api

前端 未结 12 1448
情深已故
情深已故 2021-02-02 05:58

I am searching the place in my apps using the google autocomplete place api and now I want to get latitude and longitude of the place that i have searched. How to get latitude a

12条回答
  •  被撕碎了的回忆
    2021-02-02 06:09

    Places.GeoDataApi.getPlaceById(mGoogleApiClient, placeId)
      .setResultCallback(new ResultCallback < PlaceBuffer > () {
        @Override
        public void onResult(PlaceBuffer places) {
          if (places.getStatus().isSuccess() && places.getCount() > 0) {
            final Place myPlace = places.get(0);
            Log.i(TAG, "Place found: " + myPlace.getName());
            LatLng latlangObj = myPlace.getLatLng();
            Log.v("latitude:", "" + latlangObj.latitude);
            Log.v("longitude:", "" + latlangObj.longitude);
          } else {
            Log.e(TAG, "Place not found");
          }
          places.release();
        }
      });
    

    Use this method for getting lat and lang from placeid.

提交回复
热议问题