I'm trying to return the location selected by the user in the Google Maps Android application, but I can't seem to find information about how to achieve this task.
I created an Intent to open the GMaps Activity, but the user can't select a point on the map nor does the Activity return a point to my application when it is closed.
I'm using startActiviyForResult
, since I'm expecting a result back from the Activity.
To download your data, head to Google Maps on your computer and sign in. Next, click the three-line menu icon in the top-left corner next to the Search box. Near the bottom, select “Your Data in Maps.” On the next screen, scroll down to and select “Download Your Maps Data.”
Android owners can the Google tracking feature straight out of the box. But iOS need a Google app to track your location and relay the information to the Timeline page. If you don't wish to have your location tracked, you can go to your Google account and switch off Location History.
You could simply use PlacePicker instead of implementing your own MapActivity. You will need to add Google Play Services library reference in your project though.
Just startActivityForResult with the intent provided by PlacePicker.IntentBuilder
int PLACE_PICKER_REQUEST = 1; PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder(); Context context = getApplicationContext(); startActivityForResult(builder.build(context), PLACE_PICKER_REQUEST);
And then receive the results in onActivityResult
protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == PLACE_PICKER_REQUEST) { if (resultCode == RESULT_OK) { Place place = PlacePicker.getPlace(data, this); String toastMsg = String.format("Place: %s", place.getName()); Toast.makeText(this, toastMsg, Toast.LENGTH_LONG).show(); } } }
Please refer https://developers.google.com/places/android/placepicker for further details.
A bit too late to answer your question but hope this helps someone having same requirement.
For maps API V2 you can use onMapClickListener.
map.setOnMapClickListener(new GoogleMap.OnMapClickListener() { @Override public void onMapClick(LatLng point) { Toast.makeText(getApplicationContext(), point.toString(), Toast.LENGTH_SHORT).show(); } });
For details: https://developers.google.com/maps/documentation/android/interactivity
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With