quote Tencent Map in the vue project, use the navigator.geolocation.getCurrentPosition of H5 to obtain the coordinates, and then convert the coordinates into Tencent coordinates. According to Tencent"s document, I wrote as follows:
TMap("WQCBZ-4FF3F-WI4JL-NJGAX-MECTJ-GMFWA").then(qq=>{
//
var centerPort;
//
function getLocation()
{
if (navigator.geolocation)
{
console.log("")
navigator.geolocation.getCurrentPosition(showPosition,errorHandler);
}
else{console.log("")}
}
function errorHandler(err) {
if(err.code == 1) {
alert("Error: Access is denied!");
}else if( err.code == 2) {
alert("Error: Position is unavailable!");
}
}
function showPosition(position)
{
var lat=position.coords.latitude;
var lng=position.coords.longitude;
console.log(lat);
console.log(lng);
qq.maps.convertor.translate(new qq.maps.LatLng(lat,lng), 1, function(res){
console.log(res);
//
centerPort = res[0];
})
}
getLocation();
})
is successful in getting the coordinates of gps, lat and lng, are also obtained in the method showPosition, but in executing the statement
qq.maps.convertor.translate(new qq.maps.LatLng(lat,lng), 1, function(res){
console.log(res);
//
centerPort = res[0];
})
console reported an error. The error is as follows
excuse me, why is this? How can the coordinate transformation be carried out correctly?