【发布时间】:2017-01-14 23:01:14
【问题描述】:
我正在开发一个使用地理位置坐标的应用程序。 我使用 HTML5 地理定位功能来找出网站访问者的位置,但问题在于 Chrome 不支持不安全来源的 GeoLocation。
function showPosition(){
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(function(position){
var positionInfo = "Your current position is (" + "Latitude: " + position.coords.latitude + ", " + "Longitude: " + position.coords.longitude + ")";
document.getElementById("result").innerHTML = positionInfo;
});
} else{
alert("Sorry, your browser does not support HTML5 geolocation.");
}
}
这里的代码 getCurrentPosition 无法使用,因为我的网站没有连接 SSL。
Chrome 警告: getCurrentPosition() 和 watchPosition() 不再适用于不安全的来源。要使用此功能,您应该考虑将您的应用程序切换到安全来源,例如 HTTPS。
还有其他方法可以在 chrome 上获取坐标/LatLong 值吗? [仅在不安全的连接上]
EDIT :它在我的机器上使用 localhost:80 工作,但在 http 上的测试 url 中不工作
【问题讨论】:
-
谷歌搜索。但找不到好的解决方案。
-
显而易见的问题:开始使用 HTTPS 不是一种选择……?
-
Https 是一个选项。但只是想知道是否有其他选择
-
您可以使用 Google Maps Geolocation API。
-
你可以看看gpsha.re。
标签: html geolocation