【问题标题】:Is javascript geolocation inside an html5 page calculated different for each mobile browser?每个移动浏览器计算的 html5 页面内的 javascript 地理位置是否不同?
【发布时间】:2014-08-18 06:07:38
【问题描述】:

如果我将以下代码插入 html5 页面,地理定位是否可以在 safari ios、android 和 blackberry 浏览器上工作?

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");
 }
};

我不是在问实际代码是否正确。我在问 html5 页面上的 javascript 地理定位是否适用于各种移动浏览器,或者每种浏览器是否有不同的方法(safari ios、android 和 blackberry 浏览器)

【问题讨论】:

    标签: javascript html browser geolocation


    【解决方案1】:

    有两种方法:html5 地理定位 API,其余的则使用 polyfill。
    android 和移动 safari 都不错;我实际上不得不查找黑莓,但你很好:
    http://developer.blackberry.com/html5/apis/v1_0/navigator.geolocation.html

    根据您支持的 IE 版本,modernzr 可以处理 IE8 及更高版本。
    如果您需要 IE8 以下,请使用此地理位置回退库:
    https://github.com/estebanav/javascript-mobile-desktop-geolocation/

    【讨论】:

    • 我怎样才能找到你?我需要这个项目的帮助。
    • jalbertbowden 在谷歌服务上。或者我可以跳上 irc/pidgin/whatever
    猜你喜欢
    • 2011-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-19
    • 2011-05-18
    • 1970-01-01
    相关资源
    最近更新 更多