echarts map 获取点击位置的adcode,然后调取接口

this.$nextTick(() => {
        const _this = this
        if (this.echartMap) {
          return
        }
        // 获取地图数据
        axios.get('/json/eerduosi.geoJson').then(res => {
          echarts.use([MapChart])
          echarts.registerMap('鄂尔多斯', res.data)
          this.echartMap = echarts.init(document.getElementById('test1'))
          const opotion = {
            grid: {
              top: 0,
              bottom: 0
            },
            series: [
              {
                name: '鄂尔多斯',
                type: 'map',
                mapType: '鄂尔多斯', // #3
                itemStyle: {
                  normal: { label: { show: true }},
                  emphasis: { label: { show: true }}
                },
                label: {
                  normal: {
                    textStyle: {
                      fontSize: 10
                    }
                  }
                }
              }
            ]
          }
          this.echartMap.setOption(opotion)
          // 点击事件,根据点击某个旗区计算出这个旗区的数据
          this.echartMap.on('click', function(params) {
            // 逻辑控制
            res.data.features.forEach(item => {
              if (item.properties.name === params.name) {
                item.properties.adcode // 点取位置的adcode
              }
            })
          })
        })
      })

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现根据经纬度获取地址,可以使用逆地理编码的方式,常用的逆地理编码服务有百度地图、高德地图、腾讯地图等。以下以百度地图为例,介绍如何使用百度地图API实现根据经纬度获取地址信息。 1. 首先需要在百度地图开放平台申请一个开发者账号,并创建一个应用,获取该应用的AK(访问密钥)。 2. 调用百度地图逆地理编码API,入经纬度参数,即可获取位置的地址信息。API的请求示例如下: ``` http://api.map.baidu.com/reverse_geocoding/v3/?ak=您的ak&output=json&coordtype=wgs84ll&location=纬度,经度 ``` 其中,ak为访问密钥,location为经纬度信息,示例请求如下: ``` http://api.map.baidu.com/reverse_geocoding/v3/?ak=your_ak&output=json&coordtype=wgs84ll&location=31.225696563611,121.49884033194 ``` 3. API返回的结果为JSON格式,包含了该位置的地址信息,例如: ``` { "status":0, "result":{ "location":{ "lng":121.49884033194, "lat":31.225696563611 }, "formatted_address":"上海市黄浦区南京东路街道南京东路", "addressComponent":{ "city":"上海市", "district":"黄浦区", "province":"上海市", "adcode":"310101" }, "business":"", "pois":[], "roads":[], "poiRegions":[], "sematic_description":"", "cityCode":289 } } ``` 可以从中提取出需要的地址信息,例如formatted_address为位置名称,addressComponent中的district为区,city为市,province为省,adcode为编码。 需要注意的是,不同的逆地理编码服务可能返回的结果格式和字段不同,需要根据具体的服务和API文档进行调用和解析。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值