相关疑难解决方法(0)

navigator.geolocation.getCurrentPosition有时候工作有时不会

所以我使用navigator.geolocation.getCurrentPosition jammy有一个相当简单的JS.

$(document).ready(function(){
  $("#business-locate, #people-locate").click(function() {
    navigator.geolocation.getCurrentPosition(foundLocation, noLocation);
  });

  navigator.geolocation.getCurrentPosition(foundLocation, noLocation);

  function foundLocation(position) {
    var lat = position.coords.latitude;
    var lon = position.coords.longitude;
    var userLocation = lat + ', ' + lon;
    $("#business-current-location, #people-current-location").remove();
    $("#Near-Me")
      .watermark("Current Location")
      .after("<input type='hidden' name='business-current-location' id='business-current-location' value='"+userLocation+"' />");
    $("#people-Near-Me")
      .watermark("Current Location")
      .after("<input type='hidden' name='people-current-location' id='people-current-location' value='"+userLocation+"' />");
  }
  function noLocation() {
    $("#Near-Me").watermark("Could not find location");
    $("#people-Near-Me").watermark("Could not find location");
  }
})//end DocReady
Run Code Online (Sandbox Code Playgroud)

基本上这里发生的是我们得到当前位置,如果得到的话,两个"水印"被放置在两个字段中,表示"当前位置",两个隐藏字段用lat-long数据作为它们的值(它们被删除)在一开始所以他们不会每次都重复).还有两个按钮,它们具有与之相关的点击功能,可以执行相同的操作.不幸的是,每三次左右,它都有效.这有什么问题???

javascript jquery geolocation

207
推荐指数
11
解决办法
25万
查看次数

关于HTML 5中的地理位置

现在,谷歌地图可以借助Firefox在街道精确度上精确定位我的位置.

我知道这是HTML 5兼容浏览器的一个新功能,并且通过使用连接的WiFi网络的某种功能来获取位置(我希望我没有做出任何愚蠢的假设).

我打算知道整个过程是如何工作的:

  • 为什么只在HTML 5中?
  • Firefox为何/如何让我与谷歌地图分享我的位置?
  • 可以指望的正常精度是多少?
  • 如何在我的网站中实现此功能?

提前致谢!

firefox html5 google-maps geolocation wifi

28
推荐指数
2
解决办法
1万
查看次数

哪些设备通过navigator.geolocation支持Javascript Geolocation?

iPhone通过以下调用支持移动Safari中的地理位置:

navigator.geolocation.getCurrentPosition(
  function(pos){
    var lat = pos.coords.latitude;
    var long = pos.coords.longitude;
  },
  function(){
    /* Handler if location could not be found */
  }
);
Run Code Online (Sandbox Code Playgroud)

我想建立一个包含以下其中一项的良好设备列表:

  1. 支持此功能开箱即用,或
  2. 通过升级支持此功能,或
  3. 使用其他一些Javascript片段支持具有等效数据保真度的地理定位.

我只熟悉自己的设备,所以到目前为止这是我的列表:

盒子外面:

  1. iPhone 3GS

支持,但仅限更新

  1. iPhone 3G
  2. iPhone 2G(?)
  3. 使用Firefox 3.5的PC或Mac电脑

支持其他一些代码段

Blackberry,Android手机等的支持程度如何?

javascript gps mobile-phones geolocation mobile-website

25
推荐指数
2
解决办法
3万
查看次数