【发布时间】:2020-09-06 16:57:52
【问题描述】:
我正在开发 ionic 应用程序,我想将用户从应用程序重定向到谷歌地图应用程序以向用户显示路线,但是当我将 Key restriction 设置为 NONE 时,它可以完美运行。
但是当我将限制设置为 Android apps 并提供正确的包名称和 SHA-1 时,它给了我错误:Google Maps JavaScript API error: RefererNotAllowedMapError。
我认为是因为:
ionic app is basically a webview. (which I am using)
如果这是我如何保护我的 API 密钥的原因?
我在安卓应用中使用代码打开谷歌地图是
showDirection(currentLocation, destLocation) {
let destination = destLocation.latitude + ',' + destLocation.longitude;
var directionsService = new google.maps.DirectionsService;
directionsService.route({
origin: currentLocation,
destination: destination,
travelMode: 'DRIVING'
}, function (response, status) {
if (status === 'OK') {
let mapUrl = 'http://maps.google.com/?';
var route = response.routes[0];
route.legs.forEach((value, index) => {
if (index == 0) {
mapUrl += 'saddr' + value.start_address + '&daddr=' + value.end_address;
} else {
mapUrl += '+to:' + value.end_address;
}
});
window.location.href = mapUrl;
} else {
window.alert('Directions request failed due to ' + status);
}
});
}
有人可以帮忙吗?
【问题讨论】:
标签: android google-maps ionic-framework google-api