微信jssdk 【openLocation】接口 调用时插入百度地图经纬度会导致最终显示不精确

前端之家收集整理的这篇文章主要介绍了微信jssdk 【openLocation】接口 调用时插入百度地图经纬度会导致最终显示不精确前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

项目开发中,web端调用的是百度地图api,而微信项目中调用的是腾讯自己的地图,两者所使用的坐标系有所不同,百度用的是自己的百度坐标系,而高德地图和腾讯地图使用的是火星坐标系,两者之间需要做一下转换

火星坐标 转换到 百度地图坐标
function huoxingToBaidu(hxLongitude,hxLatitude){  
                var X_PI = Math.PI * 3000.0 / 180.0;  
                var x = hxLongitude,y = hxLatitude;  
                var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * X_PI);  
                var theta = Math.atan2(y,x) + 0.000003 * Math.cos(x * X_PI);  
                var bdLongitude = z * Math.cos(theta) + 0.0065;  
                var bdLatitude = z * Math.sin(theta) + 0.006;  
                return {  
                    bdLongitude: bdLongitude,bdLatitude: bdLatitude  
                };  
            }  
百度地图坐标 转换到 火星坐标
function baiduToHuoxing(bdLongitude,bdLatitude) {  
                var X_PI = Math.Pi * 3000.0 / 180.0;  
                var x = bdLongitude - 0.0065;  
                var y = bdLatitude - 0.006;  
                var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * X_PI);  
                var theta = Math.atan2(y,x) - 0.000003 * Math.cos(x * X_PI);  
                var hxLongitude = z * Math.cos(theta);  
                var hxLatitude = z * Math.sin(theta);  
                return {  
                    hxLongitude: hxLongitude,hxLatitude: hxLatitude  
                }  
            }  

猜你在找的微信小程序相关文章