Last active
August 18, 2018 08:48
-
-
Save fulippo/357bb775b676ee073e0a to your computer and use it in GitHub Desktop.
Convert coords from Google Maps (WGS-84) to Baidu Maps (BD-09)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Convert longitude and latitude from standard WGS-84 system | |
* to Baidu's BD-09 | |
* | |
* @see http://stackoverflow.com/a/29512814/718811 for a detailed | |
* description of the problem. | |
* | |
* @param float lng Longitude | |
* @param float lat Latitude | |
* @return object Converted coords | |
*/ | |
function convertCoords(lng, lat){ | |
var x_pi = 3.14159265358979324 * 3000.0 / 180.0; | |
var x = lng, y = lat; | |
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 bd_lon = z * Math.cos(theta) + 0.0065; | |
var bd_lat = z * Math.sin(theta) + 0.006; | |
return {lng: bd_lon, lat:bd_lat}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment