微信公众号获取经纬度精确性
使用 wx.getLocation - type: "gcj02"
获取的经纬度不同机型不同,怎么提高精确性,尤其是安卓端,以下是不同机型经纬度展示
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>地图GL-DEMO</title>
</head>
<script charset="utf-8" src="https://map.qq.com/api/gljs?v=1.exp&key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77"></script>
<style type="text/css">
html,
body {
height: 100%;
margin: 0px;
padding: 0px;
}
#container {
width: 100%;
height: 100%;
}
</style>
<body onload="initMap()">
<div id="container"></div>
<script>
function initMap() {
let center = new TMap.LatLng(38.535113, 106.31457);//设置中心点坐标
//初始化地图
let map = new TMap.Map("container", {
center: center,
zoom: 12,
pitch: 30
});
map.on("click", function (event) {
let lat = event.latLng.getLat().toFixed(6);
let lng = event.latLng.getLng().toFixed(6);
console.log(lat, lng)
})
map.setViewMode('3D')
//初始化marker
let marker = new TMap.MultiMarker({
id: "marker-layer", //图层id
map: map,
styles: { //点标注的相关样式
"marker": new TMap.MarkerStyle({
"width": 25,
"height": 35,
"anchor": {x: 16, y: 32},
"src": "https://mapapi.qq.com/web/lbs/javascriptGL/demo/img/markerDefault.png"
})
},
geometries: [
{
"id": 'demo0',
"styleId": 'marker',
"position": new TMap.LatLng(38.528561, 106.319333),
"properties": {
"title": "我的位置"
}
},
{
"id": 'demo1',
"styleId": 'marker',
"position": new TMap.LatLng(38.48644, 106.23248),
"properties": {
"title": "开发者工具获取经纬度"
}
},
{
"id": 'demo2',
"styleId": 'marker',
"position": new TMap.LatLng(38.525337, 106.3211),
"properties": {
"title": "小米mix-3-4G定位"
}
},
{
"id": 'demo3',
"styleId": 'marker',
"position": new TMap.LatLng(38.528274, 106.319519),
"properties": {
"title": "iphone-6s-wifi定位"
}
},
{
"id": 'demo4',
"styleId": 'marker',
"position": new TMap.LatLng(38.528221, 106.319382),
"properties": {
"title": "iphone-8plus-4G定位"
}
},
{
"id": 'demo5',
"styleId": 'marker',
"position": new TMap.LatLng(38.526703, 106.313866),
"properties": {
"title": "小米黑鲨-4G"
}
},
{
"id": 'demo6',
"styleId": 'marker',
"position": new TMap.LatLng(38.52831, 106.319336),
"properties": {
"title": "华为荣耀"
}
}
]
});
//初始化infoWindow
let infoWindow = new TMap.InfoWindow({
map: map,
position: new TMap.LatLng(39.984104, 116.307503),
offset: {x: -3, y: -32} //设置信息窗相对position偏移像素,为了使其显示在Marker的上方
});
infoWindow.close();//初始关闭信息窗关闭
//监听标注点击事件
marker.on("click", function (evt) {
//设置infoWindow
infoWindow.open(); //打开信息窗
infoWindow.setPosition(evt.geometry.position);//设置信息窗位置
infoWindow.setContent(`<p>${evt.geometry.properties.title}</p><p>${evt.geometry.position.toString()}</p>`);//设置信息窗内容
})
}
</script>
</body>
</html>
你好,type填 wgs84 试试