Mj1992
Mj1992

Reputation: 3504

Open google maps app and show marker on it from my own apps activity

I am trying to open google maps app from my own app activity.I want to show a marker on the specific location on the maps app.What I've found till now is this piece of code.

        String label = "shop";
        String uriBegin = "geo:" + lat + "," + lng;
        String query = lat + "," + lng + "(" + label + ")";
        String encodedQuery = Uri.encode(query);
        String uriString = uriBegin + "?q=" + encodedQuery + "&z=16";
        Uri uri = Uri.parse(uriString);
        Intent intent = new Intent(android.content.Intent.ACTION_VIEW,uri);
        startActivity(intent);

What it does is opens the map app but keeps showing me a loading messagebox saying searching for:<lat>,<lng>(shop) where <lat> and <lng> are my provided values . Whats wrong with this ?

I've copied this code from another stackoverflow post.

Upvotes: 3

Views: 6122

Answers (1)

Tachikoma
Tachikoma

Reputation: 351

Update your google maps App.

Then (if isn't already working), you can try with this code:

String uri = String.format(Locale.ENGLISH, "geo:%f,%f?z=17&q=%f,%f", latitude,longitude,latitude,longitude);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));

Based on the question of: Starting Google Maps App with provided location and marker to get that the marker appears adding the query tag to the URI

Upvotes: 8

Related Questions