Omkar Phadke
Omkar Phadke

Reputation: 27

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.

Upvotes: 0

Views: 338

Answers (1)

user2711811
user2711811

Reputation:

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

Upvotes: 1

Related Questions