解析经纬度

记录

-- 解析经纬度

select

split(regexp_extract('POINT(120.400870660833 27.500001565702)','([0-9.]+ [0-9.]+)'),' ')[2],

split(regexp_extract('POINT(120.400870660833 27.500001565702)','([0-9.]+ [0-9.]+)'),' ')[1]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以使用高德地图的 JavaScript API 中的 `AMap.Geocoder` 类来实现地址解析经纬度。 首先,在你的 Nuxt.js 项目中安装高德地图的 JavaScript API: ```bash npm install @amap/amap-jsapi-loader ``` 然后,在你的 Vue 组件中引入并使用 `AMap.Geocoder` 类: ```vue <template> <div> <input type="text" v-model="address" /> <button @click="search">搜索</button> <div v-if="latitude && longitude"> 纬度:{{ latitude }} 经度:{{ longitude }} </div> </div> </template> <script> import AMapLoader from '@amap/amap-jsapi-loader'; export default { data() { return { address: '', latitude: null, longitude: null, }; }, methods: { async search() { const AMap = await AMapLoader.load({ key: 'YOUR_AMAP_API_KEY', version: '2.0', }); const geocoder = new AMap.Geocoder({ city: '全国', }); geocoder.getLocation(this.address, (status, result) => { if (status === 'complete' && result.geocodes.length) { const { lat, lng } = result.geocodes[0].location; this.latitude = lat; this.longitude = lng; } else { console.error('解析地址失败'); } }); }, }, }; </script> ``` 这里使用了 `@amap/amap-jsapi-loader` 包来动态加载高德地图的 JavaScript API,然后通过 `AMap.Geocoder` 类的 `getLocation` 方法将地址解析经纬度,并将结果存储在组件的 `latitude` 和 `longitude` 数据中。需要注意的是,在 `AMap.Geocoder` 的构造函数中需要传入一个 `city` 参数,表示解析地址时所在的城市,这里使用了 `全国` 表示在全国范围内解析地址。如果你知道要解析的地址所在的城市,可以将其传入该参数。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值