zoukankan      html  css  js  c++  java
  • webpack中 VUE使用百度地图获取地理位置

    百度地图

    1、index.html中引入 百度地图api

    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=key"></script>

    2、在webpack.base.conf.js里面 配置

    module.exports = {
    context: path.resolve(__dirname, '../'),
    entry: {
    app: './src/main.js'
    },
    externals: {
    "BMap": "BMap"
    },
    }

    3、引入使用,一定记住需要在mounted钩子函数里面操作API 因为地图需要在所以的dom树加载完毕后才能操作

     import BMap from 'BMap'
      export default {
        data() {
          location: null
        },
        mounted() {
          let _this = this
          var geolocation = new BMap.Geolocation()
          geolocation.getCurrentPosition(function(r) {
            if (this.getStatus() == BMAP_STATUS_SUCCESS) {
              const myGeo = new BMap.Geocoder()
              myGeo.getLocation(new BMap.Point(r.point.lng, r.point.lat), data => {
                if (data.addressComponents) {
                  const result = data.addressComponents
                  const location = {
                    creditLongitude: r.point.lat, // 经度
                    creditLatitude: r.point.lng, // 纬度
                    creditProvince: result.province || '', //
                    creditCity: result.city || '', //
                    creditArea: result.district || '', //
                    creditStreet: (result.street || '') + (result.streetNumber || '') // 街道
                  }
                  _this.location = location
                }
              })
            }
          })
        }
    }
  • 相关阅读:
    unidac使用演示
    delphi序列化对象的方法总结
    ReadFileToBuffer
    unidac连接ORACLE免装客户端驱动
    WriteFileFromBuffer
    mvc模式
    unidac宏替换使用
    如何使用Navicat监控mysql数据库服务器
    环信(php)服务器端REST API
    laravel 框架接入环信遇到的坑()
  • 原文地址:https://www.cnblogs.com/jackjo/p/9706897.html
Copyright © 2011-2022 走看看