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
Based on the latest version of AutoComplete documentation
Option 1: Embed an AutocompleteSupportFragment
AutocompleteSupportFragment autocompleteFragment = (AutocompleteSupportFragment)
getSupportFragmentManager().findFragmentById(R.id.autocomplete_fragment);
autocompleteFragment
.setPlaceFields(Arrays.asList(Place.Field.ID,
Place.Field.NAME,Place.Field.LAT_LNG,Place.Field.ADDRESS));
Option 2: Use an intent to launch the autocomplete activity
List fields = Arrays.asList(Place.Field.ID, Place.Field.NAME,Place.Field.LAT_LNG,Place.Field.ADDRESS);
// Start the autocomplete intent.
Intent intent = new Autocomplete.IntentBuilder(
AutocompleteActivityMode.FULLSCREEN, fields)
.build(this);
startActivityForResult(intent, AUTOCOMPLETE_REQUEST_CODE);
whichever fields you are interested in, you have to mention as mentioned above.
You'll get result as below:
onPlaceSelected:
{
"a":"#90, 1st Floor, Balaji Complex, Kuvempu Main Road, Kempapura, Hebbal
Kempapura, Bengaluru, Karnataka 560024, India",
"b":[],
"c":"ChIJzxEsY4QXrjsRQiF5LWRnVoc",
"d":{"latitude":13.0498176,"longitude":77.600347},
"e":"CRAWLINK Networks Pvt. Ltd."
}
Note: The result displayed is by parsing the Place object to json