uniapp - 微信小程序利用腾讯地图插件实现搜索地点/位置功能,uniapp小程序平台端使用腾讯地图做搜索城市位置+底部自动根据关键字联想其他相关位置(详细示例源码,一键复制开箱即用!)

效果图

在uniapp微信小程序开发中,安装使用腾讯地图插件,并利用腾讯地图功能完成目的地、城市位置、名称等搜索功能,并且在下拉框中自动 “联想” 相关的地点位置。

uniapp Vue3和Vue2都能用,最终效果图有点模糊,你可以按照教程一路复制就可以搞定了。

在这里插入图片描述

一:准备开始

  • 13
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
可以使用uniapp地图组件来实现将图片地图功能。具体的步骤如下: 1. 在uniapp中引入地图组件 在uniapp的页面中,可以引入uniapp自带的地图组件,代码如下: ``` <template> <view class="map"> <map :longitude="longitude" :latitude="latitude" :markers="markers" :covers="covers" style="width: 100%; height: 100%;"></map> </view> </template> <script> import uniMap from '@/components/uni-map/uni-map.vue' export default { components: { uniMap }, data () { return { longitude: 116.397128, latitude: 39.916527, markers: [{ id: 0, longitude: 116.397128, latitude: 39.916527, title: 'Marker', iconPath: '/static/map/marker.png', width: 50, height: 50 }], covers: [] } } } </script> ``` 2. 将图片转换成地图 将图片转换成地图需要借助第三方API,比如阿里云地图API、腾讯地图API等,这里以阿里云地图API为例,具体的步骤如下: (1)在阿里云地图API上创建一个应用,获取到应用的AppCode。 (2)使用uniapp的网络请求API,将图片上传到阿里云OSS,并获取到图片的URL。 (3)将图片的URL作为参数,调用阿里云地图API的静态地图API,获取地图图片,并将图片显示在地图上。 具体的代码实现如下: ``` <template> <view class="map"> <map :longitude="longitude" :latitude="latitude" :markers="markers" :covers="covers" style="width: 100%; height: 100%;"></map> </view> </template> <script> import uniMap from '@/components/uni-map/uni-map.vue' import { request } from '@/utils/request' export default { components: { uniMap }, data () { return { longitude: 116.397128, latitude: 39.916527, markers: [{ id: 0, longitude: 116.397128, latitude: 39.916527, title: 'Marker', iconPath: '/static/map/marker.png', width: 50, height: 50 }], covers: [] } }, mounted () { this.getMap() }, methods: { async getMap () { try { // 1. 将图片上传到阿里云OSS,获取图片的URL const res = await uni.uploadFile({ url: 'https://oss-cn-hangzhou.aliyuncs.com', filePath: '/static/map/map.jpg', name: 'file', formData: { key: 'map.jpg', policy: '', OSSAccessKeyId: '', success_action_status: '200', signature: '' } }) const url = `https://xxx.aliyuncs.com/${res.data.key}` // 2. 调用阿里云地图API,获取地图图片 const appCode = 'xxxxxx' const { data } = await request({ url: `https://restapi.amap.com/v3/staticmap?location=${this.longitude},${this.latitude}&zoom=10&size=750*400&markers=mid,,A:${this.longitude},${this.latitude}&key=${appCode}&icon=${url}` }) // 3. 将地图图片显示在地图上 this.covers = [{ id: 0, longitude: this.longitude, latitude: this.latitude, iconPath: data, width: 750, height: 400 }] } catch (error) { console.log(error) } } } } </script> ``` 以上就是使用uniapp实现将图片地图功能的全部步骤。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

街尾杂货店&

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值