腾讯地图定位

智者不为愚者谋,勇者不为怯者死。这篇文章主要讲述腾讯地图定位相关的知识,希望能为你提供帮助。

var lat;
var long;
var _this = this
if (navigator.geolocation)
navigator.geolocation.getCurrentPosition(onSuccess, onError);
else
alert("您的浏览器不支持使用html 5来获取地理位置服务");

//定位数据获取成功响应
function onSuccess(position)
// alert(纬度:+ position.coords.latitude + \\n +
//经度:+ position.coords.longitude + \\n +
//海拔:+ position.coords.altitude + \\n +
//水平精度:+ position.coords.accuracy + \\n +
//垂直精度:+ position.coords.altitudeAccura)


//定位数据获取失败响应
function onError(error)
switch (error.code)
case error.PERMISSION_DENIED:
alert("您拒绝对获取地理位置的请求");
break;
case error.POSITION_UNAVAILABLE:
alert("位置信息是不可用的");
break;
case error.TIMEOUT:
alert("请求您的地理位置超时");
break;
case error.UNKNOWN_ERROR:
alert("未知错误");
break;


var geolocation = new qq.maps.Geolocation("GJNBZ-PMO64-C3PUZ-XFSPG-L7RXO-7FBSD", "myapp");
var positionNum = 0;
var options =
timeout: 15000
;
var geocoder;
var latLng;

function showPosition(position)
let latitude = position.lat;
let longitude = position.lng;
// 逆地址解析(经纬度到地名转换过程)
geocoder = new qq.maps.Geocoder(
complete: function(res)
console.log(789789);
console.log(res);
// 标志位置
var center = new qq.maps.LatLng(latitude, longitude);
var map = new qq.maps.Map(document.getElementById(container),
center: center,
zoom: 13
);
//创建标记
var marker = new qq.maps.Marker(
position: center,
map: map
);
//添加到提示窗
var info = new qq.maps.InfoWindow(
map: map
);
//获取标记的点击事件
qq.maps.event.addListener(marker, click, function()
info.open();
info.setContent( + res.detail.address + );
info.setPosition(center);
);



var reJson = JSON.parse(JSON.stringify(res));
console.log(11111)
console.log(reJson)

var address =
address.province = reJson.detail.addressComponents.province;
address.city = reJson.detail.addressComponents.city;
address.district = reJson.detail.addressComponents.district;
address.street = reJson.detail.addressComponents.town+reJson.detail.addressComponents.street+reJson.detail.addressComponents.streetNumber;

_this.address1 = address.street



);
latLng = new qq.maps.LatLng(latitude, longitude);
;


function showErr()
console.log(定位失败);

geolocation.getLocation(showPosition, showErr, options);

document.addEventListener(plusready, geolocation.getLocation(showPosition, showErr, options),false);


 
【腾讯地图定位】


    推荐阅读