|
|
@ -26,18 +26,25 @@ function calculateDistance(lat1, lon1, lat2, lon2) { //计算两点距离 |
|
|
|
|
|
|
|
function getLocation(fn) { //获取用户经纬度
|
|
|
|
wxGetLocation() //此方法只用于提示用户打开gps
|
|
|
|
uni.getLocation({ |
|
|
|
type: 'gcj02', |
|
|
|
isHighAccuracy: true, |
|
|
|
highAccuracyExpireTime: 1000, |
|
|
|
success: function(position) { |
|
|
|
fn(position) |
|
|
|
}, |
|
|
|
fail: function() { //使用ip获取定位
|
|
|
|
let key = config.mapKey; //腾讯地图key
|
|
|
|
getUserAddressByIp(key).then(res => { |
|
|
|
fn(res.position) //返回经纬度
|
|
|
|
}) |
|
|
|
// uni.getLocation({
|
|
|
|
// type: 'gcj02',
|
|
|
|
// isHighAccuracy: true,
|
|
|
|
// highAccuracyExpireTime: 1000,
|
|
|
|
// success: function(position) {
|
|
|
|
// fn(position)
|
|
|
|
// },
|
|
|
|
// fail: function() { //使用ip获取定位
|
|
|
|
// let key = config.mapKey; //腾讯地图key
|
|
|
|
// getUserAddressByIp(key).then(res => {
|
|
|
|
// fn(res.position) //返回经纬度
|
|
|
|
// })
|
|
|
|
// }
|
|
|
|
// })
|
|
|
|
|
|
|
|
uni.getFuzzyLocation({ |
|
|
|
type: 'wgs84', |
|
|
|
success (res) { |
|
|
|
fn(res) |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
@ -46,20 +53,25 @@ function getLocationDetail() { //获取用户详细地址 |
|
|
|
wxGetLocation() |
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
let key = config.mapKey; //腾讯地图key
|
|
|
|
uni.getLocation({ |
|
|
|
type: 'gcj02', |
|
|
|
isHighAccuracy: true, |
|
|
|
highAccuracyExpireTime: 1000, |
|
|
|
success: function(position) { |
|
|
|
getUserAddress(position.latitude, position.longitude, key).then(res => { |
|
|
|
resolve(res) |
|
|
|
}) |
|
|
|
}, |
|
|
|
fail: function() { //使用ip获取定位
|
|
|
|
getUserAddressByIp(key).then(res => { |
|
|
|
resolve(res) |
|
|
|
}) |
|
|
|
} |
|
|
|
// uni.getLocation({
|
|
|
|
// type: 'gcj02',
|
|
|
|
// isHighAccuracy: true,
|
|
|
|
// highAccuracyExpireTime: 1000,
|
|
|
|
// success: function(position) {
|
|
|
|
// getUserAddress(position.latitude, position.longitude, key).then(res => {
|
|
|
|
// resolve(res)
|
|
|
|
// })
|
|
|
|
// },
|
|
|
|
// fail: function() { //使用ip获取定位
|
|
|
|
// getUserAddressByIp(key).then(res => {
|
|
|
|
// resolve(res)
|
|
|
|
// })
|
|
|
|
// }
|
|
|
|
// })
|
|
|
|
getLocation((position) => { |
|
|
|
getUserAddress(position.latitude, position.longitude, key).then(res => { |
|
|
|
resolve(res) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
@ -151,20 +163,20 @@ function wxGetLocation(successCallback, failCallback) { |
|
|
|
|
|
|
|
// #endif
|
|
|
|
console.log('wx.getLocation'); |
|
|
|
wx.getLocation({ |
|
|
|
type: 'gcj02', |
|
|
|
isHighAccuracy: true, |
|
|
|
highAccuracyExpireTime: 2000, |
|
|
|
success(res) {}, |
|
|
|
fail(err) { |
|
|
|
if(err.errMsg == 'getLocation:gps closed'){ |
|
|
|
uni.showToast({ |
|
|
|
title: '请打开GPS定位,否则定位不准确', |
|
|
|
icon: 'none' |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
// wx.getLocation({
|
|
|
|
// type: 'gcj02',
|
|
|
|
// isHighAccuracy: true,
|
|
|
|
// highAccuracyExpireTime: 2000,
|
|
|
|
// success(res) {},
|
|
|
|
// fail(err) {
|
|
|
|
// if(err.errMsg == 'getLocation:gps closed'){
|
|
|
|
// uni.showToast({
|
|
|
|
// title: '请打开GPS定位,否则定位不准确',
|
|
|
|
// icon: 'none'
|
|
|
|
// })
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// })
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|