Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get selected location from Google Maps activity

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.

like image 329
foliveira Avatar asked Dec 13 '10 14:12

foliveira


People also ask

How do I extract Google location data?

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.”

Can I track my phone's location history?

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.


2 Answers

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.

like image 179
Sudhanshu Gupta Avatar answered Sep 17 '22 12:09

Sudhanshu Gupta


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

like image 38
Faruk Toptas Avatar answered Sep 17 '22 12:09

Faruk Toptas