腾讯地图微信小程序JDK文档地址:https://lbs.qq.com/miniProgram/jsSdk/jsSdkGuide/methodGetsuggestion
高德地图微信小程序JDK文档地址:https://lbs.amap.com/api/wx/summary/
// 腾讯地图经纬度转百度地图经纬度
qqMapTransBMap(lng,lat){
let x_pi = 3.14159265358979324 * 3000.0 / 180.0;
let x = lng;
let y = lat;
let z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi);
let theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
let lngs = z * Math.cos(theta) + 0.0065;
let lats = z * Math.sin(theta) + 0.006;
return {
lng: lngs,
lat: lats
}
},
// 百度地图经纬度转腾讯地图经纬度
bMapTransQQMap(lng,lat){
let x_pi = 3.14159265358979324 * 3000.0 / 180.0;
let x = lng - 0.0065;
let y = lat - 0.006;
let z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
let theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
let lngs = z * Math.cos(theta);
let lats = z * Math.sin(theta);
return {
lng: lngs,
lat: lats
}
},
// 计算两个点(经纬度)的距离
getGreatCircleDistance(lng1,lat1,lng2,lat2) {
/**
* lng1,lat1:第一个点的坐标
* lng2,lat2:第二个点的坐标
*/
var EARTH_RADIUS = 6378137.0;
var PI = Math.PI;
function getRad(d) {
return d * PI / 180.0;
}
var radLat1 = getRad(lat1);
var radLat2 = getRad(lat2);
var a = radLat1 - radLat2;
var b = getRad(lng1) - getRad(lng2);
var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
s = s * EARTH_RADIUS;
s = Math.round(s * 10000) / 10000.0;
return Math.abs(s);// 米
},,
//预处理判断 某个点是否在某个区域
preceedPointInArea(lng, lat, points) {
/**
* 调用:app.preceedPointInArea(116.57088516503416,40.00419042847179,points)
* lng,lat:某个点的坐标
* points:区域 ->数据格式:[{latitude: 40.002437265807984,longitude: 116.57233411463574},{latitude: 40.003028239422505,longitude: 116.56579786205464},{latitude: 40.00626208747302,longitude: 116.56485492741547}];这个区域由多少个点,这里就传多少个点
*/
var parking_gps = points;
var gpsStringArray = parking_gps;
var polygon = [];
for(var i=0;i<gpsStringArray.length;i++){
var item = gpsStringArray[i];
var point = {};
point['lng'] = parseFloat(item["longitude"]);
point['lat'] = parseFloat(item["latitude"]);
polygon.push(point);
}
var flag = this.isPointInPolygon(polygon, lng, lat);
return flag;
},
//某个点是否在某个区域 上面preceedPointInArea函数调用该函数
isPointInPolygon(polygon, lng, lat) {
var numberOfPoints = polygon.length;
var polygonLats = [];
var polygonLngs = [];
for (var i = 0; i < numberOfPoints; i++) {
polygonLats.push(polygon[i]['lat']);
polygonLngs.push(polygon[i]['lng']);
}
var polygonContainsPoint = false;
for (var node = 0, altNode = (numberOfPoints - 1); node < numberOfPoints; altNode = node++) {
if ((polygonLngs[node] > lng != (polygonLngs[altNode] > lng))
&& (lat < (polygonLats[altNode] - polygonLats[node])
* (lng - polygonLngs[node])
/ (polygonLngs[altNode] - polygonLngs[node])
+ polygonLats[node]
)
) {
polygonContainsPoint = !polygonContainsPoint;
}
}
return polygonContainsPoint;
},
有误差,不过还能接收,如果有更加精确的,请留言,学习一下