app使用谷歌地图,使用uni.chooseLocation,在安卓上可以扒拉地图获取一个位置,在苹果上不能这样操作,是为什么呢?或者有没有其他选择位置的方法?求解
8***@qq.com
- 发布:2024-11-14 17:40
- 更新:2024-11-20 13:54
- 阅读:26
8***@qq.com (作者)
使用nvue 在地图上点击位置获取经纬度解析地址,在iOS上正常,但在安卓上会闪退
<template>
<view class="chooseAddressnvue">
<map id="map" class="map" @tap="tap" :latitude="lat" :longitude="lng" @markertap="makertap" @poitap="tap" :markers="makers"></map>
<view class="address">
<view class="">当前位置</view>
<view class="">{{address.name}}</view>
</view>
<image src="../../static/icon/sure.png" mode="widthFix" class="confirm" @click="done" v-if="address.name"></image>
</view>
</template>
<script>
import http from '../../utils/http';
export default {
data() {
return {
lat:'',
lng:'',
name:'',
address:{
city:'',
province:'',
district:'',
name:'',
lat:'',
lng:''
}
}
},
onLoad(option) {
//获取当前位置
http.getLocation().then(res=>{
console.log("getlocation",res);
this.address=res
this.lat=res.lat
this.lng=res.lng
this.$forceUpdate()
})
},
computed:{
makers(){
return [
{
id:1,
latitude:this.lat,
longitude:this.lng,
iconPath:'/static/icon/address.png',
width:30,
height:30
}
]
}
},
methods: {
// 点击地图位置
tap(e){
console.log("当前位置",e);
this.lat=e.detail.latitude
this.lng=e.detail.longitude
//解析位置
http.post('user/getlocation',{
lat: e.detail.latitude,
lng: e.detail.longitude
}).then(res=>{
console.log("解析位置",res);
console.log(res.data.city);
let city = res.data.city;
let province = res.data.province;
let district = res.data.district;
let name = res.data.result[0].formatted_address
let data = {
city:city,
province:province,
district:district,
name:name,
lat:this.lat,
lng:this.lng
};
console.log("address",data);
this.address=data
console.log("address",this.address);
this.name=data.name
this.$set(this.address,'name',data.name)
this.$forceUpdate()
})
},
makertap(e){
console.log("点击marker",e);
},
done(){
const eventChannel = this.getOpenerEventChannel();
eventChannel.emit('acceptDataFromOpenedPage', this.address);
uni.navigateBack()
}
}
}
</script>
这是nvue页面的代码,安卓上点击进入这个页面会闪退,百度搜说是安卓手机不兼容谷歌地图