Javascript html5 geoloaction在chrome/windows7中不起作用。但是它在chrome/XP中工作……html5有什么问题吗
我正在创建一个只在chrome中工作的混合应用程序。在我的应用程序中,我使用HTML5地理定位。这在chrome/XP中运行良好,但在chrome/Windows7中不起作用。。。在执行下面的函数时,它请求我允许使用当前位置。我单击了“允许”,但之后没有响应。我找不到实际问题。请帮我解决Javascript html5 geoloaction在chrome/windows7中不起作用。但是它在chrome/XP中工作……html5有什么问题吗,javascript,jquery,html,geolocation,currentlocation,Javascript,Jquery,Html,Geolocation,Currentlocation,我正在创建一个只在chrome中工作的混合应用程序。在我的应用程序中,我使用HTML5地理定位。这在chrome/XP中运行良好,但在chrome/Windows7中不起作用。。。在执行下面的函数时,它请求我允许使用当前位置。我单击了“允许”,但之后没有响应。我找不到实际问题。请帮我解决 if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(self.showPosition); function showP
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(self.showPosition);
function showPosition(position)
{
var currentLatitude = position.coords.latitude;
var currentLongitude = position.coords.longitude;
localStorage.DeviceLocation=currentLatitude+","+currentLongitude;
$("#curr_loc_target").html("<b>Current location enabled as target </b> <BR> <b>Latitude :</b> "+currentLatitude.toFixed(5)+" <b>Longitude : </b>"+currentLongitude.toFixed(5));
$("#curr_loc_target").show();
}
}
if(navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(self.showPosition);
功能显示位置(位置)
{
var currentLatitude=位置坐标纬度;
var currentLength=position.coords.longitude;
localStorage.DeviceLocation=currentLatitude+“,”+CurrentLength;
$(“#curr#u loc_target”).html(“当前位置作为目标启用
纬度:+currentLatitude.toFixed(5)+”经度:+currentLatitude.toFixed(5));
$(“当前位置目标”).show();
}
}
这会给出您要查找的错误。它在我的chrome win 7上不起作用,错误是在本地运行时拒绝用户权限,但上传到服务器时不允许。您可能会尝试将其放到服务器上,而不是使用文件:///协议运行。我们应该做到这一点。Chrome在本地运行时,对其允许的功能感到恼火
$(document).ready(function(){
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, showError);
function showPosition(position) {
var currentLatitude = position.coords.latitude;
var currentLongitude = position.coords.longitude;
alert(currentLongitude);
localStorage.DeviceLocation=currentLatitude+","+currentLongitude;
$("#curr_loc_target").html("<b>Current location enabled as target </b> <BR> <b>Latitude :</b> "+currentLatitude.toFixed(5)+" <b>Longitude : </b>"+currentLongitude.toFixed(5));
$("#curr_loc_target").show();
}
} else {
alert("geoloc not working");
}
function showError(error) {
var x = $('#curr_loc_target');
switch(error.code) {
case error.PERMISSION_DENIED:
x.html("User denied the request for Geolocation.");
break;
case error.POSITION_UNAVAILABLE:
x.html("Location information is unavailable.");
break;
case error.TIMEOUT:
x.html("The request to get user location timed out.");
break;
case error.UNKNOWN_ERROR:
x.html("An unknown error occurred.");
break;
}
}
});
$(文档).ready(函数(){
if(导航器.地理位置){
navigator.geolocation.getCurrentPosition(showPosition,showError);
功能显示位置(位置){
var currentLatitude=位置坐标纬度;
var currentLength=position.coords.longitude;
警报(当前经度);
localStorage.DeviceLocation=currentLatitude+“,”+CurrentLength;
$(“#curr#u loc_target”).html(“当前位置作为目标启用
纬度:+currentLatitude.toFixed(5)+”经度:+currentLatitude.toFixed(5));
$(“当前位置目标”).show();
}
}否则{
警报(“geoloc不工作”);
}
功能错误(错误){
变量x=$('当前位置目标');
开关(错误代码){
案例错误。权限被拒绝:
x、 html(“用户拒绝了地理定位请求”);
打破
案例错误。位置不可用:
x、 html(“位置信息不可用”);
打破
大小写错误。超时:
x、 html(“获取用户位置的请求超时”);
打破
案例错误。未知错误:
x、 html(“发生未知错误”);
打破
}
}
});
控制台中是否出现任何错误?(ctrl+shift+j)