Open google maps from hyperlink
Asked Answered
R

3

34

I am trying to design a webpage specially for android users so i was wondering if there is a hyper link format that can open up google maps just like the call function eg

<a href="tel:0766551121"> Call me now </a>
Radmen answered 18/4, 2012 at 7:11 Comment(0)
U
49

If by "open up Google Maps" you mean the native Android Google Maps application instead of opening the link in the Android's browser then according to Geo Intents you can use the following Geo URI formats that trigger intents that will open the Google Maps application on the device to the given location or query:

  • geo:latitude,longitude
  • geo:latitude,longitude?z=zoom
  • geo:0,0?q=my+street+address
  • geo:0,0?q=business+near+city

For Google Streetview you can use:

  • google.streetview:cbll=lat,lng&cbp=1,yaw,,pitch,zoom&mz=mapZoom

For details on the available options see the official Google Maps Intents documentation

Understand answered 18/4, 2012 at 7:37 Comment(5)
I sent myself a mail with the first format but doesn't work. It tries to open it with browsers instead.Abb
By far the best comment i found on the net about this topic, thanks sir !Epigone
it is also possible to open maps as navigation with walk mode? so user do not have to click on "get directions"Grip
@Grip Yes, you have to append the "&mode=w" parameter, For more information see this . I've also updated the response to include the official docs links for the Google Maps intents.Understand
Can I also put a pin in the map in this way?Kingofarms
S
13

use GEO URI for open a map on hyper link click like:

<a href="geo:37.786971,-122.399677;u=35">open map</a>
Streamliner answered 18/4, 2012 at 7:14 Comment(0)
E
4

I am going with @Mnemonic Flow

  • geo:latitude,longitude
  • geo:latitude,longitude?z=zoom
  • geo:0,0?q=my+street+address
  • geo:0,0?q=business+near+city

Create your Uri

Example

Step 1 : Create link like

Uri uri; 
  • geo:latitude,longitude

    uri = Uri.parse("geo:47.6,-122.3")

  • geo:latitude,longitude?z=zoom

    uri = Uri.parse("geo:47.6,-122.3?z=11")

  • geo:0,0?q=my+street+address

    uri = Uri.parse("geo:0,0q=The+Eldorado+Park,+Rampar+Mota,+Gujarat,+India")

  • geo:0,0?q=business+near+city

    uri = Uri.parse("geo:0,0q=The+Eldorado+Park,+Rampar+Mota,+Gujarat,+India")

Step 1 Create method like below

public void showMap(Uri geoLocation) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(geoLocation);
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    }
}

And Call like this

showMap(uri);

Step 2 : Add intent-filter in you manifiest file

<activity YourActivity>
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <data android:scheme="geo" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>
Endoparasite answered 21/11, 2016 at 7:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.