Angular2 引用高德地图

(1)在全局中引用高德地图api(楼主在index.html 里引用)

<script src="http://webapi.amap.com/maps?v=1.4.6&key=你的高德key值"></script>

(2)在各个组件中引用高德地图

component.ts 文件

  public ngOnInit() {
    const mapObj = new AMap.Map('mapviewcontainer', {
      resizeEnale: true,
      zoom: 15,
      center: [113.592618, 22.942735]
    });
}

.html 文件

  <div class="page-wrapper">
    <div style="width: 100%; height: 100%;padding-top: 44px;">
      <div id="mapviewcontainer" style="width: 1730px; height: 900px;"></div>
    </div>
  </div>

这就可以简单地引用高德地图了

当引用高德地图的插件时,Angular会报不是其构造函数,此时需在引用api时加上对应的插件即可,例如引用高德的逆向解析地址: AMap.Geocoder

<script src="http://webapi.amap.com/maps?v=1.4.6&key=你的高德key值&plugin=AMap.Geocoder"></script>
let geocoder = new AMap.Geocoder();
          geocoder.getAddress(lnglatXY, (status, result) => {
            if (status === 'complete' && result.info === 'OK') {
              this.addressname = result.regeocode.formattedAddress;
            }
          });

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值