1.解決報(bào)當(dāng)前定位失敗Geolocation permission denied:
?
?可以去高德api查看:常見問題 | 高德地圖API (amap.com)
?
圖中紅圈2,3,4,5,6對(duì)應(yīng)Geolocation permission denied報(bào)錯(cuò)的原因,可對(duì)應(yīng)修改。
如紅圈2:用戶打開定位選項(xiàng)即可:
?
?2.進(jìn)入定位頁(yè)面偶爾報(bào) AMap沒有找到的。
1.在index.html文件中;
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.12&key=自己的key">
window.AMap = AMap;
</script>
2.在封裝高德api的文件下對(duì)應(yīng)調(diào)整:文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-524628.html
/**
* 用高德地圖定位
*/
amapLocate(
complete?: (cityCode: string, cityName: string) => void,
error?: () => void
): void {
const AMap = (window as any).AMap;
const mapObj = new AMap.Map("iCenter");
mapObj.plugin("AMap.Geolocation", () => {
const geolocation = new AMap.Geolocation({
timeout: 100000, // 超過 100 秒后停止定位
});
mapObj.addControl(geolocation);
geolocation.getCurrentPosition();
AMap.event.addListener(
geolocation,
"complete",
(data: {
position: { lat: number; lng: number };
addressComponent: { adcode?: string; province: string; city: string };
}) => {
const position = data.position;
const addressComponent = data.addressComponent;
this.LocationModule.SET_longitude_PERSIST(position.lng);
this.LocationModule.SET_latitude_PERSIST(position.lat);
if (complete) {
complete(
getCityCodeByAdcode(
addressComponent
? addressComponent.adcode
: LocationModule.defaultCityCode
),
addressComponent
? addressComponent.city || addressComponent.province
: LocationModule.defaultCityName // 直轄市 addressComponent.city 為空字符串,這時(shí)要取 province
);
}
}
);
AMap.event.addListener(geolocation, "error", (errorData: unknown) => {
console.error("locate >>> errorData", errorData);
this.LocationModule.SET_longitude_PERSIST(-1);
this.LocationModule.SET_latitude_PERSIST(-1);
if (error) {
error();
}
});
});
}
?文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-524628.html
到了這里,關(guān)于H5頁(yè)面在ios的瀏覽器上使用 高德地圖 報(bào)當(dāng)前定位失敗Geolocation permission denied 或者 偶爾報(bào)AMap沒有找到的的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!