Created
December 25, 2016 16:25
-
-
Save bh-lay/6506ff263df51829b907aa2e5a2940ba to your computer and use it in GitHub Desktop.
各地图产品间的坐标转换
This file contains hidden or 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
| //1、GCJ-02,国测局02年发布的坐标体系。又称“火星坐标”。谷歌,腾讯,高德都在用这个坐标体系。 | |
| //2、BD-09,百度坐标系 | |
| //BD-09转换GCJ-02 | |
| function baiduToGCJ($lat, $lng){ | |
| var $v = Math.PI * 3000.0 / 180.0; | |
| var $x = $lng - 0.0065; | |
| var $y = $lat - 0.006; | |
| var $z = Math.sqrt($x * $x + $y * $y) - 0.00002 * Math.sin($y * $v); | |
| var $t = Math.atan2($y, $x) - 0.000003 * Math.cos($x * $v); | |
| return { | |
| lat: $z * Math.sin($t), | |
| lng: $z * Math.cos($t) | |
| } | |
| } | |
| //使用方法 | |
| var $lat = 32.134632; | |
| var $lng = 114.088683; | |
| var $coordinate = baiduToGCJ($lat, $lng); |
This file contains hidden or 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
| //GCJ-02转换BD-09 | |
| function GCJTobaidu($lat, $lng){ | |
| var $v = Math.PI * 3000.0 / 180.0; | |
| var $x = $lng; | |
| var $y = $lat; | |
| var $z = Math.sqrt($x * $x + $y * $y) + 0.00002 * Math.sin($y * $v); | |
| var $t = Math.atan2($y, $x) + 0.000003 * Math.cos($x * $v); | |
| return { | |
| lat: $z * sin($t) + 0.006, | |
| lng: $z * cos($t) + 0.0065 | |
| }; | |
| } | |
| //使用方法 | |
| var $lat = 32.1287736098; | |
| var $lng = 114.082163843; | |
| var $coordinate = GCJTobaidu($lat, $lng); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment