Question

Is there a way with JavaScript to check whether the client-browser supports the GEO-URI-scheme?

I want to show a coordinate for nonsupported browsers as a link to a map

<a href='http://osm.org/#map=18/52.51627/13.37769'>Berlin</a>

and for supported browsers (like smartphones) as a link to their own native apps.

<a href='geo:52.51627,13.37769'>Berlin</a>
Was it helpful?

Solution

No, there isn't. Wether or not the geo protocol is available isn't up to the browser, but the underlying OS. Android's browser has no idea if it can support it, it asks the subsystem if it has a handler for the geo URI, and if so, open it. The only way to know that the system supports a custom uri would be to try and open a link, and seeing if it works. There wouldn't be a way to do this automatically without completely interrupting the user.

A good example on the best way to do this would be Apple's maps.apple.com. They use server-side UA sniffing to redirect maps.apple.com to the best site available.

Trying to go to http://maps.apple.com/?q=cupertino on any mavericks browser will result in them sending a 302 to a maps:// url (the custom URI for the Maps.app app). Same for iOS devices. If it is an unrecognized browser, it will redirect to the corresponding maps.google.com address, since they don't have their own maps web presence.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top