Question

I can't seem to find a common answer anywhere. It seems like there isn't a way to support both Android and iPhone for links opening in their native maps application with their current location set.

From what I've been able to find, the iPhone does it like this:

saddr=Current%20Location

and android you can just leave "saddr" blank. I'm not even thinking of BlackBerries yet. I suppose there is probably a way to do this with JavaScript, but it don't think it should be that complicated.

Was it helpful?

Solution

For now what I'm doing is using html5 geolocation to grab the latitude and longitude instead relying on the OS to interpret the current location.

HTML:

 <a id="directions" class="callout" href="http://maps.google.com/maps?daddr=address">

JavaScript:

$('#directions').bind('click', function (e) {
    var href = $(this).attr('href');
    if (navigator.geolocation) {
        e.preventDefault();
        navigator.geolocation.getCurrentPosition(function (position) {
            geoLink(position.coords.latitude, position.coords.longitude, href);
        });
    }

    function geoLink(lat, log, href) {
        var location = href + '&saddr=' + lat + ',' + log;
        window.location.href = location;
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top