Link to iPhone map App from HTML page
Asked Answered
B

4

10

Is there a way to link to directions in the iPhone map app from a html page?

We're placing an add in an iPhone app which will link to a mobile page on our website - we'd like to add a directions link, thus far google searches have been unrevealing.

Behah answered 27/7, 2011 at 7:21 Comment(0)
P
6

Here is a javascript function that creates the link:

function mapLink(myAddress) {
    return 'http://maps.google.com/maps?q='+escape(myAddress);
}

This works great on the iPhone.

Pyroxene answered 20/1, 2012 at 19:21 Comment(2)
In new versions of ios this needs to be a reference to maps.apple.com. something like: maps.apple.com/?q=cupertinoAsceticism
Which now redirects back to Google maps.Slap
G
13

A link to http://maps.google.com/maps will automatically open in the map application

You can set a destination address (daddr) and start address (saddr) in the link:

http://maps.google.com/maps?daddr=San+Francisco,+CA&saddr=cupertino

You can see some more options at:

https://developer.apple.com/library/archive/featuredarticles/iPhoneURLScheme_Reference/MapLinks/MapLinks.html

Godship answered 28/7, 2011 at 23:19 Comment(1)
As per the latest version of the docs, this needs to be a link to maps.apple.comAsceticism
P
6

Here is a javascript function that creates the link:

function mapLink(myAddress) {
    return 'http://maps.google.com/maps?q='+escape(myAddress);
}

This works great on the iPhone.

Pyroxene answered 20/1, 2012 at 19:21 Comment(2)
In new versions of ios this needs to be a reference to maps.apple.com. something like: maps.apple.com/?q=cupertinoAsceticism
Which now redirects back to Google maps.Slap
B
4

If you use the standard link that would display a map in the browser, it will automatically open in Google Maps on the device. That includes links that show directions.

Bushbuck answered 27/7, 2011 at 7:29 Comment(0)
T
2

Use something like:

<a href='maps:daddr=<destination>&saddr=Current%20Location'>Directions</a>

where may be a lat/lon pair (separated by a comma) or a place. Ensure you URI encode the destination to ensure it works.

Teniers answered 17/9, 2012 at 16:26 Comment(1)
can you show an example with an actual address? I am trying to do this but the map application always returns back with an error?Jeggar

© 2022 - 2024 — McMap. All rights reserved.