• 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>


  • 相关阅读:
    文件隐藏在一张图片里
    晶振
    主宰全球的10大算法
    java+mysql连接的优化
    排序剔除
    js数据类型
    字符实体
    表单
    定义样式表
    布局相关的属性
  • 原文地址:https://www.cnblogs.com/gerry/p/11049474.html
Copyright © 2020-2023  润新知