You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.2 KiB

//
import gcoord from "./gcoord.js";
import { jsonp } from 'vue-jsonp'
const getNowAddress = () => {
let that = this;
let nowAddress = {
latitude:"",
longitude:"",
address:""
}
uni.getLocation({
type: "wgs84",
geocode: true,
success(res) {
var loc = null
console.log(typeof(window.android))
if (typeof(window.android) != undefined && typeof(window.android) != "undefined") {
loc = window.android.getLocInfo();
}
if (loc) {
nowAddress.latitude = JSON.parse(loc).lat;
nowAddress.longitude = JSON.parse(loc).lon;
} else {
nowAddress.latitude = res.latitude;
nowAddress.longitude = res.longitude;
}
let _latlog = gcoord.transformFromWGSToGCJ(nowAddress.latitude,nowAddress.longitude);
console.log(_latlog)
const url =
"https://apis.map.qq.com/ws/geocoder/v1/?key=PCBBZ-2Y4L5-V6AIY-Q2LHL-FSGLT-ZRBL6&location=" +
_latlog.latitude + "," + _latlog.longitude + "&output=jsonp"
jsonp(
url
).then(re => {
nowAddress.address = re.result.formatted_addresses.recommend
return nowAddress
})
console.log(nowAddress)
}
})
}
module.exports = {
getNowAddress:getNowAddress
};