get Lat Lang from a place_id returned by autocomplete place api

前端 未结 12 1447
情深已故
情深已故 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:16

    do provide Place.Field.LAT_LNG to get the latitude and longitude for the place.

     autocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, 
     Place.Field.NAME,Place.Field.LAT_LNG));
    

    then get LatLng

    LatLng destinationLatLng = place.getLatLng();
    

    and can see through toast

     destlat = destinationLatLng.latitude;
     destLon = destinationLatLng.longitude;
     Toast.makeText(getApplicationContext(), "" + destlat + ',' + destLon, Toast.LENGTH_LONG).show();
    

提交回复
热议问题