简体   繁体   中英

How to add marker to a specific location in Google Maps in Android Studio?

I have created a button which takes the user to a specific location on Google Maps. Here is the snippet:

String uri = String.format(Locale.ENGLISH, "geo:%f,%f", latitude, longitude);
                        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
                        context.startActivity(intent);

However, the Map merely zooms to the particular location without adding a marker to the co-ordinates I have put. Can someone please help me?

Thank You.

This works for me (the 'hellothere' is a label you can replace or remove):

String uri = String.format(Locale.ENGLISH, "geo:0,0?q=%f,%f(hellothere)",latitude,longitude);

UPDATE: the geo: parameter can be 0,0 when supplying a location query.

(When testing you may want to close the Map app each test particularly if not moving the marker.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM