17

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>
bfncs
  • 10,007
  • 4
  • 32
  • 52
cyper
  • 436
  • 4
  • 12

1 Answers1

8

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.

Patrick
  • 13,872
  • 5
  • 35
  • 53
  • There's a promising [polyfill](https://github.com/prowestgis/dojo-geo-uri-polyfill) (depending on Dojo) out there, also relying on client-side UA sniffing. It might make sense to use [Apple Maps Links](https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/MapLinks/MapLinks.html) as a fallback instead of Google Maps, though. – bfncs Sep 23 '15 at 14:21
  • is there a difference from apple maps links and what I suggested? – Patrick Sep 24 '15 at 15:55
  • No it didn't? I say everything you mention – Patrick Sep 25 '15 at 18:35
  • I totally get that - I just don't understand what you added. All of the facts you mention are things in my answer. – Patrick Sep 27 '15 at 05:07
  • The link to [dojo-geo-uri-polyfill](https://github.com/prowestgis/dojo-geo-uri-polyfill) and the comment on how this should better be modified (by using Apple Maps instead of Google Maps as a fallback). Why exactly do we discuss this in that length? I'm going to delete all follow up comments to make it more graspable for anyone else again. – bfncs Sep 28 '15 at 05:55