简体   繁体   中英

Is javascript geolocation inside an html5 page calculated different for each mobile browser?

If I insert the following code into an html5 page will the geolocation work on safari ios, android and blackberry browsers?

getViaHtml5 = function(done) {
 if(navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(function(position) {
  vicinity.lat = position.coords.latitude;
  vicinity.lng = position.coords.longitude;
  done();
 }, function(e) {
  console.warn('ERROR(' + e.code + '): ' + e.message);
  });
 } else {
  console.warn("Browser doesn't support Geolocation");
 }
};

I'm not asking if the actual code is correct. I'm asking if javascript geolocation on an html5 page will work for the various mobile browsers or is there a different method for each browser (safari ios, android and blackberry browsers)

there are two methods: the html5 geolocation api, and polyfill(s) for the rest.
android, and mobile safari are good to go; i actually had to look up blackberry, but you're good:
http://developer.blackberry.com/html5/apis/v1_0/navigator.geolocation.html

depending on what version(s) of IE you support, modernzr handles IE8 and up.
If you need below IE8 use this geolocation fallback library:
https://github.com/estebanav/javascript-mobile-desktop-geolocation/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM