【发布时间】:2018-04-07 13:08:43
【问题描述】:
在我的应用程序中需要获取当前位置,我尝试使用下面的代码,我得到了位置未定义之类的错误。获取 API 对象“位置”本身的错误未定义。
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。
我已附上屏幕截图以获取更多信息。
【问题讨论】:
-
获取 API 对象“位置”本身的错误未定义。
标签: javascript jquery google-maps