Javascript navigator.geolocation.getCurrentPosition(位置)获取错误“;“未定义位置”;
在我的应用程序需要获得当前位置时,我尝试了以下代码,我得到的错误类似于位置未定义。获取API对象“位置”本身时发生的错误未定义Javascript navigator.geolocation.getCurrentPosition(位置)获取错误“;“未定义位置”;,javascript,jquery,google-maps,Javascript,Jquery,Google Maps,在我的应用程序需要获得当前位置时,我尝试了以下代码,我得到的错误类似于位置未定义。获取API对象“位置”本身时发生的错误未定义 try { if (event.handled !== true) { event.handled = true; if (navigator.geolocation) { var geoOptions = { enableHighAccuracy: true, timeout: 20000 };
try {
if (event.handled !== true) {
event.handled = true;
if (navigator.geolocation) {
var geoOptions = { enableHighAccuracy: true, timeout: 20000 };
navigator.geolocation.getCurrentPosition(function (position) { // geoSuccess
$("#clientPersonalDetailesDiv #longitude").val(position.coords.longitude);
$("#clientPersonalDetailesDiv #latitude").val(position.coords.latitude);
$.hcmobile.hideLoader();
}, function (error) { // geoError
$.hcmobile.hideLoader();
if (error.code == '3') {
$.hcmobile.alertBox("ErrorMessage", "GPS is not available on this device");
}
else {
$.hcmobile.alertBox("ErrorMessage", error.message + 'You must turn on location services to use this feature');
//$.hcmobile.alertBox("ErrorMessage", "You must turn on location services to use this feature");
}
}, geoOptions);
}
}
}
catch (e)
{
}
我得到错误代码1,它说:
getCurrentPosition()和watchPosition()不再适用于不安全的源。要使用这个特性,您应该考虑将应用程序切换到安全的原点,例如HTTPS.< /P>。
我附上了更多信息的屏幕截图
如您的错误所述,使用此功能仅在安全连接(通过https提供)上有效。阅读以供参考。获取API对象“位置”本身时发生的错误未定义。