uniapp+腾讯地图和高德地图

1. 先注册高德api和腾讯位置服务,获取咱们需要的key和安全密钥

直接搜索就可以需要注册的东西,点击控制台--应用管理/我的应用--创建新应用

2. 创建好uniapp项目后,先进manifest.json文件中,点击web配置,选择最下面定位和地图,需要用哪个地图就用哪个地图

要注意这里的高德,key和安全密钥都需要,最下面的代理地址和第二个都写安全密钥就可以

3.接着创建个页面输入代码就可以

<template>
	<view>
		<map :latitude="latitude" :longitude="longitude" show-compass="true" show-location="true" class="map"></map>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				latitude: 0,
				longitude: 0,
			}
		},
		onLoad() {
			uni.getLocation({
				type: 'gcj02',
				geocode: true,
				isHighAccuracy: true,
				success: (res) => {
					console.log("获取经纬度成功");
					this.latitude = res.latitude;
					this.longitude = res.longitude;
					console.log(this.latitude);
					console.log(this.longitude);
				},
				fail: () => {
					console.log("获取经纬度失败");
				},
				complete: () => {
					// 解析地址
					QQMapWX.reverseGeocoder({
						location: {
							latitude: this.latitude,
							longitude: this.longitude
						},
						success: function(res) {
							console.log("解析地址成功");
							console.log(res);
							// 省
							let province = res.result.ad_info.province;
							// 市
							let city = res.result.ad_info.city;
							console.log(province);
							console.log(city);
						},
						fail: function(res) {
							uni.showToast({
								title: '定位成功',
								duration: 2000,
								icon: "none"
							})
							console.log(res);
						},
						complete: function(res) {
							console.log(res);
						}
					})
				}
			})
		},
		methods: {

		}
	}
</script>

<style>
	.map {
		width: 100vw;
		height: 90vh;
	}
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值