全部
常见问题
产品动态
精选推荐

高德地图实现点击地图添加标记,通过输入框搜索详细地址自动定位到指定位置

管理 管理 编辑 删除

高德地图api版本:JavaScript API V2.0.05dd9320230727101316981.png

用高德地图实现输入搜索地址 添加标记,鼠标移动标记来获取当前该点的经纬度,详细地址

1. 高德地图的页面构建:首先先引入高德地图,增加自己想要的功能,我们这里需要一个输入联想框

944ba202307271017038938.png

2. 高德地图的Api来实现相关功能

1. 构建地图

  initMap() {
      const that = this
      return new Promise((reslove, reject) => {
        AMapLoader.load({
          key: 'cf5c437b14780406af75a81b380cafac',
          version: '2.0',
          plugins: [
            'AMap.ToolBar',
            'AMap.Scale',
            'AMap.Geocoder',
            'AMap.Geolocation',
            'AMap.PlaceSearch',
            'AMap.AutoComplete',
            'AMap.CitySearch'
          ],
          resizeEnable: true
        }).then((AMap) => {
          that.map = new AMap.Map('allmap', {
            resizeEnable: true,
            zoom: 14,
            viewMode: '3D', //使用3D视图
            center: [that.positionInfo.lng, that.positionInfo.lat]
          })
          that.getCurrentLocation()
          that.map.addControl(new AMap.Scale()) // 在图面添加比例尺控件,展示地图在当前层级和纬度下的比例尺
          that.map.addControl(new AMap.ToolBar()) //在图面添加鹰眼控件,在地图右下角显示地图的缩略图
          that.geocoder = new AMap.Geocoder({ radius: 1000, extensions: 'all', city: '全国' })
          that.mapSearchInit()
          that.geocoder.getAddress([that.positionInfo.lng, that.positionInfo.lat], function (status, result) {
            if (status === 'complete' && result.regeocode) {
              that.address = result.regeocode.formattedAddress
            } else {
              that.$message.error('根据经纬度查询地址失败')
            }
          })
        })
      })
    },


2. 根据输入框内容搜索地点,经纬度

  searchKeyWord() {
      let that = this
      that.placeSearchComponent.search(that.address, function (status, result) {
        if (status === 'complete' && result.info === 'OK') {
          that.show = true
          // 关键字联想的选项内容
          that.poiList = result.poiList.pois
        } else {
          that.showsearchResult = false
          that.poiList = []
          that.$message({
            message: '没有查到结果',
            type: 'warning'
          })
        }
      })
    },

3. 动态设置点标记,构造矢量圆形

 dynamicSign(lng, lat, radius) {
      var marker = new AMap.Marker({
        position: new AMap.LngLat(lng, lat), //参数为经纬度
        draggable: true,
        cursor: 'move',
        riseOnHover: true,
        bubble: true,
        cursor: 'pointer'
      })
      // 构造矢量圆形
      const circle = new AMap.Circle({
        center: new AMap.LngLat(lng, lat), // 圆心位置
        radius: radius, //半径
        strokeColor: '#1890ff', //线颜色
        strokeOpacity: 1, //线透明度
        strokeWeight: 1, //线粗细度
        fillColor: '#1890ff', //填充颜色
        fillOpacity: 0.35 //填充透明度
      })
      this.map.clearMap()
      this.map.add([marker, circle]) // 添加点标志
      marker.on('dragend', this.markerClick)
    },

 高德地图api接口比较丰富,大多的需求都能实现。本次主要使用了POI搜索插件AMap.PlaceSearch,获取城市信息AMap.getCityInfo,设置标记点AMap.Marker,构造矢量图AMap.Circle结合了带列表的POI搜索的这个,再将监听事件改为列表点选的selectChange事件,获得当前点选地点经纬度,这样将二者进行了组合一下实现了以上的搜索以及展现方式。


请登录后查看

怎么网名又被占用了 最后编辑于2023-07-27 10:34:20

快捷回复
回复({{post_count}}) {{!is_user ? '我的回复' :'全部回复'}}
回复从新到旧

{{item.user_info.nickname ? item.user_info.nickname : item.user_name}}

作者 管理员 企业

{{item.floor}}# 同步到gitee 已同步到gitee {{item.is_suggest==1? '取消推荐': '推荐'}}
{{item.floor}}#
{{item.user_info.title}}
附件

{{itemf.name}}

{{item.created_at}}  {{item.ip_address}}
{{item.like_count}}
{{item.showReply ? '取消回复' : '回复'}}
删除
回复
回复

{{itemc.user_info.nickname}}

{{itemc.user_name}}

作者 管理员 企业

回复 {{itemc.comment_user_info.nickname}}

附件

{{itemf.name}}

{{itemc.created_at}}   {{itemc.ip_address}}
{{itemc.like_count}}
{{itemc.showReply ? '取消回复' : '回复'}}
删除
回复
回复
查看更多
回复
回复
3271
{{like_count}}
{{collect_count}}
添加回复 ({{post_count}})

相关推荐

怎么网名又被占用了 管理员
有什么心结解不开,就把它系成蝴蝶结!

回答

27

发布

4

经验

380

快速安全登录

使用微信扫码登录
{{item.label}} {{item.label}} {{item.label}} 板块推荐 常见问题 产品动态 精选推荐 首页头条 首页动态 首页推荐
加精
取 消 确 定
回复
回复
问题:
问题自动获取的帖子内容,不准确时需要手动修改. [获取答案]
答案:
提交
bug 需求 取 消 确 定

微信登录/注册

切换手机号登录

{{ bind_phone ? '绑定手机' : '手机登录'}}

{{codeText}}
切换微信登录/注册
暂不绑定
CRMEB客服

CRMEB咨询热线 咨询热线

400-8888-794

微信扫码咨询

CRMEB开源商城下载 开源下载 CRMEB官方论坛 帮助文档
返回顶部 返回顶部
CRMEB客服