在uniapp h5中怎么使用在线引入高德地图js api

//这里要加window., loadScrpit的callback才会执行

window.mapInit = function(){
  let mapObj = new AMap.Map('iCenter');
  mapObj.plugin('AMap.Geolocation', function () {
      let geolocation = new AMap.Geolocation({
          enableHighAccuracy: false,//是否使用高精度定位,默认:true
          timeout: 5000,          //超过5秒后停止定位,默认:无穷大
      });
      mapObj.addControl(geolocation);
      geolocation.getCurrentPosition();
      //返回定位信息
      AMap.event.addListener(geolocation, 'complete', function (res) {
          console.log(res);
      });
      //返回定位出错信息
      AMap.event.addListener(geolocation, 'error', function (err) {
          console.log(err);
      });
  });
}

// 页面onload调用此方法

function loadScrpit(){
  var script = document.createElement('script');
  script.src = "https://webapi.amap.com/maps?v=1.4.15&key=您申请的key值&callback=mapInit";
  document.body.appendChild(script);
}

你可能感兴趣的:(uniapp)