I rather thought that it would not be so difficult to find, but it seems not easy to find an awesome cross-device article, as you would expect.
I want to create a link that opens either a mobile browser, or surfing on Google maps, or open a map application (Apple Maps or Google Maps) and start the route directly, that is: start from the current location, (lat / long).
I can test on two devices (next to the browser), Android and iPhone.
The following link only works on Android:
<a href="http://maps.google.com/maps?daddr=lat,long&ll=">Take me there!</a>
By clicking this link in iPhone Chrome, it strangely opens Google Maps in the desktop version with ads in the mobile application ...
This only works on iOS, opening Apple Maps, prompting me to enter the starting location (I can select "Current Location") and start the route = desired behavior. Clicking this link completely failed on Android:
<a href="maps://maps.google.com/maps?daddr=lat,long&ll=">Take me there!</a>
Pay attention to the maps: // protocol.
Is there an elegant way to cross-device to create such a link? One link that works on all major mobile phones
thank
UPDATE: solution found (kinda)
Here is what I came up with. This is not exactly what I imagined, although it works.
var ua = navigator.userAgent.toLowerCase(), plat = navigator.platform, protocol = '', a, href; $.browser.device = ua.match(/android|webos|iphone|ipad|ipod|blackberry|iemobile|opera/i) ? ua.match(/android|webos|iphone|ipad|ipod|blackberry|iemobile|opera/i)[0] : false; if ($.browser.device) { switch($.browser.device) { case 'iphone': case 'ipad': case 'ipod': function iOSversion() { if (/iP(hone|od|ad)/.test(navigator.platform)) { // supports iOS 2.0 and later: <http://bit. ly/TJjs1V> var v = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/); return [parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)]; } } var ver = iOSversion() || [0]; if (ver[0] >= 6) { protocol = 'maps://'; } else { protocol = 'http://maps.google.com/maps'; } break; case 'android': default: protocol = 'http://maps.google.com/maps'; break; } a.attr('href', protocol + href)
The maps:// protocol is a URL scheme for the apple maps application, which will only work on ios 6 or higher. There are ways to check if gmaps is installed, and then choose what to do with the URL, but that was too much for what I intended. So I just created a map: // OR maps.google.com/ using the above options.
** UPDATE **
Unfortunately, $ .browser.device does not work since jquery 1.9 (source - http://api.jquery.com/jquery.browser )