【发布时间】:2019-05-29 07:56:03
【问题描述】:
我正在尝试使用 Cordova 地理定位插件获取带有地址的当前位置。但我收到以下错误消息。 {error_message:“您必须使用 API 密钥来验证每个请求...,请参阅 http://g.co/dev/maps-no-account”,结果:Array(0),状态:“REQUEST_DENIED”} error_message: "您必须使用 API 密钥来验证对 Google Maps Platform API 的每个请求。有关其他信息,请参阅http://g.co/dev/maps-no-account" 结果: [] 状态:“REQUEST_DENIED”
获取当前位置。下面我使用的代码请更正我的代码
$scope.init = 函数 () {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
if (navigator.connection.type == Connection.NONE) {
} else {
}
var networkConnection = navigator.connection.type;
if (networkConnection != null) {
navigator.geolocation.getCurrentPosition(success, error);
}
else {
alert('Please check your network connection and try again.');
}
}
function success(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
getDetails(latitude, longitude);
}
function error(error) {
alert('Please check your network connection and try again.');
}
function getDetails(latitude, longitude) {
var url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" + latitude + "," + longitude + "&sensor=false";
$.getJSON(url, function (data) {
console.log(data);
});
}
请更正我的代码,我希望将当前位置与地址一起输出。感谢您的提前。
【问题讨论】:
-
您必须使用 API 密钥来验证对 Google Maps Platform API 的每个请求。我想知道如何才能更清楚。
标签: javascript jquery google-maps cordova geolocation