基于vue/typeScript的百度地图应用

2,001 阅读1分钟

1、BMap引入

    (1)在

index.html中引入百度地图API,并在"你的密钥"中填写自己的密钥。

<script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=你的密钥"></script>

   (2)在需要引入BMap的vue文件里引入。

const BMap = window.BMap || {};

2、获取用户所在城市信息

const geo = new BMap.LocalCity();  
geo.get((result: any) => {
   console.log(console.log(result))
});

3、获取用户地理位置信息

const geo = new BMap.getLocation();  
getLocation.get((result: any) => {
   console.log(console.log(result))
});

4、根据经纬度获取用户具体位置信息

const myGeo = new BMap.Geocoder();
myGeo.getLocation(new BMap.Point(this.longitude, this.latitude), (result: any) => {  if ( result ) {     this.city =  result.address;  }});