3

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.

Community
  • 1
  • 1
Mj1992
  • 3,404
  • 13
  • 63
  • 102
  • hopefully your code is working well, there might be two reasons 1. Your lat/lon is somewhat wrong 2. Internet Connection problem. I was having the same isuue for some lat/lon. – Anuj Sharma Mar 29 '13 at 10:06
  • yes you are right . I open the google maps app from the menu seperately and it is still not showing the map.Although my other apps are working fine . I am getting notifications and my google play app is running.That means internet connection is also fine. So only this map app is not working properly . Do you know the reason ? – Mj1992 Mar 29 '13 at 10:10

1 Answers1

8

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

Community
  • 1
  • 1
Tachikoma
  • 351
  • 4
  • 5