Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
238 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...