2012-08-07 129 views
3

我正在尝试使用HTML5地理定位API;但我有问题,使其在Firefox浏览器和铬工作:HTML5地理位置在Firefox,Chrome和Chromium中不起作用


init(); 

function init() {; 
    // Get the current location 
    getPosition();  
} 

function getPosition() { 
    navigator.geolocation.getCurrentPosition(success, fail,{ 
     enableHighAccuracy:true, 
     timeout:10000, 
     maximumAge:Infinity 
    });  
} 

function success(position) { 
    alert("Your latitude: " + position.coords.latitude + "longitude: " 
     + position.coords.longitude); 
} 

function fail(e) { 
    alert("Your position cannot be found"+e.code+" => "+e.message); 
} 

在IE9和Safari它的工作完美无瑕;但:

  • 在Firefox(v13和V14)存在错误代码3(超时)在铬和铬(V20和V21)
  • 有和错误代码2与消息“网络的位置信息提供在'https://maps.googleapis.com/maps/api/browserlocation/json?browser=googlechrome&sensor=true':响应格式错误。“

我有全新的Chrome安装(今天安装在Windows XP上,没有扩展),我已经授权在浏览器中的地理位置。

你可以在那里尝试一下: http://jsfiddle.net/mhj82/38/

是否有解决方案,使其在所有的浏览器支持地理定位的工作吗?

+0

厂在Mac上使用Chrome v21适用于我 – Kevin 2012-08-07 12:56:35

+0

我已经要求一些朋友测试这个jsfiddle,它似乎适用于其中一些,但这并不能解释它为什么不能在这里工作:( – Molochdaa 2012-08-07 13:42:04

+0

你有没有发现问题是什么?我有同样的问题... @Molochdaa – dotnethaggis 2013-08-29 20:21:19

回答

0

你看过这个吗? http://code.google.com/p/chromium/issues/detail?id=41001

在线程结束时,他们得出结论:为了在Chrome中工作,必须在具有工作WiFi适配器的设备上执行地理定位。

在您的电脑上启用了wifi吗?

(不知道为Firefox)

+0

是的,我已经在带有WiFi适配器的Mac OS X上的Chrome中进行了测试,并且无法正常工作。 – Molochdaa 2012-08-07 09:44:19

0

我不得不等待,直到该文件被加载让它在Chrome浏览器

jQuery().ready(function() { 
    if (navigator.geolocation) { 
     navigator.geolocation.getCurrentPosition.... 
    } 
}); 
0

尝试在Chrome桌面这个测试,移动

if (navigator.geolocation) { 
    var latitude = null; 
    var longitude = null; 
    navigator.geolocation.getCurrentPosition(function (position) { 
     latitude = position.coords.latitude; 
     longitude = position.coords.longitude; 
    }); 



} else { 
    alert("Geolocation API is not supported in your browser"); 
}; 
相关问题