zoukankan      html  css  js  c++  java
  • vue引入高德地图获取经纬度地址

    1、在index.html引入高德地图

    <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.4&key=your key"></script> //key找个适合例如:160cab8ad6c50752175d76e61ef92c50



    2、在webpack.base.conf.js 配置引入

    externals: {
    'AMap': 'AMap',
    }

    3、在vue文件中使用

    <template>
    <div id="my_container"></div>
    </template>
    <script>
    import AMap from 'AMap'

    export default {
    name: "company_manage",
    data () {
    return {
    ruleForm: {
    name: '',
    phone: '',
    addr: '',
    long: '',
    lat: '',
    start_work_time: '',
    end_work_time: '',
    },
    }
    },
    mounted:function () {
    this.init()
    },
    methods: {
    init() {
    var map = new AMap.Map('my_container',{
    resizeEnable: true,
    zoom: 18,
    })
    AMap.plugin('AMap.Geolocation',function(){ //异步加载插件
    var geolocation = new AMap.Geolocation()
    map.addControl(geolocation)
    })
    var geocoder,marker;
    function regeocoder(lnglatXY,that) {
    AMap.plugin('AMap.Geocoder',function(){
    var geocoder = new AMap.Geocoder({
    radius: 1000,
    extensions: "all"
    });
    geocoder.getAddress(lnglatXY, function(status, result) {
    if (status === 'complete' && result.info === 'OK') {
    var address = result.regeocode.formattedAddress;
    that.ruleForm.addr = address  //兑换地址
    }
    });
    if(!marker){
    marker = new AMap.Marker();
    map.add(marker);
    }
    marker.setPosition(lnglatXY);
    })
    }
    var that = this
    map.on('click', function(e) {
    var lnglatXY = [e.lnglat.getLng(),e.lnglat.getLat()];
    regeocoder(lnglatXY,that)
    that.ruleForm.long = e.lnglat.getLng()
    that.ruleForm.lat = e.lnglat.getLat()
    });
    },
    },
    }
    </script>

    <style scoped>
    #my_container{
    margin-left: 140px;
    height: 400px;
    calc(100% - 140px);
    }
    </style>


  • 相关阅读:
    对于近期学习上的复习与整理
    ACM的奇计淫巧_输入挂
    hdu2602 DP (01背包)
    hdu 1723 DP/递推
    hdu1428 记忆化搜索(BFS预处理最短路径和+DP+DFS)
    hdu1355
    hdu1331&&hdu1579记忆化搜索(DP+DFS)
    hdu1257 dp(最长上升子序列)
    hdu1208 dp
    hdu 1203 dp(关于概率的```背包?)
  • 原文地址:https://www.cnblogs.com/gerry/p/11049474.html
Copyright © 2011-2022 走看看