基於vue/typeScript的百度地圖應用

一、BMap引入javascript

    (1)在html

index.html中引入百度地圖API,並在"你的密鑰"中填寫本身的密鑰。

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

   (2)在須要引入BMap的vue文件裏引入。vue

const BMap = window.BMap || {};複製代碼

二、獲取用戶所在城市信息java

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

三、獲取用戶地理位置信息git

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

四、根據經緯度獲取用戶具體位置信息
api

const myGeo = new BMap.Geocoder();
myGeo.getLocation(new BMap.Point(this.longitude, this.latitude), (result: any) => {  if ( result ) {     this.city =  result.address;  }});複製代碼
相關文章
相關標籤/搜索