下面代码兼容安卓APP和H5
高德地图官网:我的应用 | 高德控制台 ,绑定服务选择《Web端(JS API)》
/utils/map.js 需要设置你自己的key和安全密钥
export function myAMap() {
return new Promise(function(resolve, reject) {
if (typeof window.onLoadMyAMap === 'function') {
resolve(window.onLoadMyAMap)
return
}
window.onLoadMyAMap = function() {
resolve(window.onLoadMyAMap)
}
window._AMapSecurityConfig = {
securityJsCode: '你的安全密钥',
};
var script = document.createElement('script')
script.type = 'text/javascript'
script.src =
`https://webapi.amap.***/maps?v=2.0&key=你的key&callback=onLoadMyAMap&plugin=AMap.Geocoder,AMap.Auto***plete,AMap.PlaceSearch`
script.onerror = reject
document.head.appendChild(script)
})
}
页面代码
<template>
<view class="gaodeMap">
<view class="map" v-bind:styl