{"id":1124,"date":"2018-08-12T17:05:00","date_gmt":"2018-08-12T09:05:00","guid":{"rendered":"http:\/\/www.luwl.net\/?p=1124"},"modified":"2018-08-12T17:05:00","modified_gmt":"2018-08-12T09:05:00","slug":"gps%e5%9d%90%e6%a0%87%e8%bd%ac%e6%8d%a2php%e7%89%88%e6%9c%ac","status":"publish","type":"post","link":"http:\/\/www.luwl.net\/?p=1124","title":{"rendered":"GPS\u5750\u6807\u8f6c\u6362php\u7248\u672c"},"content":{"rendered":"<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\r\n&lt;?php\r\n\/**\r\n* WGS84\u4e0e\u767e\u5ea6\u5750\u6807\u7cfb (BD-09) \u7684\u8f6c\u6362\r\n*\/\r\nfunction wgs84tobd09($lng, $lat){\r\n$cj2=wgs84togcj02($lng,$lat);\r\nreturn gcj02tobd09($cj2&#x5B;0],$cj2&#x5B;1]);\r\n};\r\n\/**\r\n* \u706b\u661f\u5750\u6807\u7cfb (GCJ-02) \u4e0e\u767e\u5ea6\u5750\u6807\u7cfb (BD-09) \u7684\u8f6c\u6362\r\n* \u5373\u8c37\u6b4c\u3001\u9ad8\u5fb7 \u8f6c \u767e\u5ea6\r\n*\/\r\nfunction gcj02tobd09($lng, $lat) {\r\n$x_PI = 3.14159265358979324 * 3000.0 \/ 180.0;\r\n$lat = +$lat;\r\n$lng = +$lng;\r\n$z = sqrt($lng * $lng + $lat * $lat) + 0.00002 * sin($lat * $x_PI);\r\n$theta = atan2($lat, $lng) + 0.000003 * cos($lng * $x_PI);\r\n$bd_lng = $z * cos($theta) + 0.0065;\r\n$bd_lat = $z * sin($theta) + 0.006;\r\nreturn &#x5B;$bd_lng, $bd_lat];\r\n};\r\n\/**\r\n* WGS84\u8f6cGCj02\r\n*\/\r\nfunction wgs84togcj02($lng, $lat) {\r\n$ee = 0.00669342162296594323;\r\n$a = 6378245.0;\r\n$lat = +$lat;\r\n$lng = +$lng;\r\nif (out_of_china($lng, $lat)) {\r\nreturn &#x5B;$lng, $lat];\r\n} else {\r\n$dlat = transformlat($lng - 105.0, $lat - 35.0);\r\n$dlng = transformlng($lng - 105.0, $lat - 35.0);\r\n$radlat = $lat \/ 180.0 * M_PI;\r\n$magic = sin($radlat);\r\n$magic = 1 - $ee * $magic * $magic;\r\n$sqrtmagic = sqrt($magic);\r\n$dlat = ($dlat * 180.0) \/ (($a * (1 - $ee)) \/ ($magic * $sqrtmagic) * M_PI);\r\n$dlng = ($dlng * 180.0) \/ ($a \/ $sqrtmagic * cos($radlat) * M_PI);\r\n$mglat = $lat + $dlat;\r\n$mglng = $lng + $dlng;\r\nreturn &#x5B;$mglng, $mglat];\r\n}\r\n};\r\nfunction transformlat($lng, $lat) {\r\n$lat = +$lat;\r\n$lng = +$lng;\r\n$ret = -100.0 + 2.0 * $lng + 3.0 * $lat + 0.2 * $lat * $lat + 0.1 * $lng * $lat + 0.2 * sqrt(abs($lng));\r\n$ret += (20.0 * sin(6.0 * $lng * M_PI) + 20.0 * sin(2.0 * $lng * M_PI)) * 2.0 \/ 3.0;\r\n$ret += (20.0 * sin($lat * M_PI) + 40.0 * sin($lat \/ 3.0 * M_PI)) * 2.0 \/ 3.0;\r\n$ret += (160.0 * sin($lat \/ 12.0 * M_PI) + 320 * sin($lat * M_PI \/ 30.0)) * 2.0 \/ 3.0;\r\nreturn $ret;\r\n};\r\n\r\nfunction transformlng($lng, $lat) {\r\n$lat = +$lat;\r\n$lng = +$lng;\r\n$ret = 300.0 + $lng + 2.0 * $lat + 0.1 * $lng * $lng + 0.1 * $lng * $lat + 0.1 * sqrt(abs($lng));\r\n$ret += (20.0 * sin(6.0 * $lng * M_PI) + 20.0 * sin(2.0 * $lng * M_PI)) * 2.0 \/ 3.0;\r\n$ret += (20.0 * sin($lng * M_PI) + 40.0 * sin($lng \/ 3.0 * M_PI)) * 2.0 \/ 3.0;\r\n$ret += (150.0 * sin($lng \/ 12.0 * M_PI) + 300.0 * sin($lng \/ 30.0 * M_PI)) * 2.0 \/ 3.0;\r\nreturn $ret;\r\n};\r\n\/**\r\n* \u5224\u65ad\u662f\u5426\u5728\u56fd\u5185\uff0c\u4e0d\u5728\u56fd\u5185\u5219\u4e0d\u505a\u504f\u79fb\r\n*\/\r\nfunction out_of_china($lng, $lat) {\r\n$lat = +$lat;\r\n$lng = +$lng;\r\n\/\/ \u7eac\u5ea63.86~53.55,\u7ecf\u5ea673.66~135.05\r\nreturn !($lng &gt; 73.66 &amp;&amp; $lng &lt; 135.05 &amp;&amp; $lat &gt; 3.86 &amp;&amp; $lat &lt; 53.55);\r\n};\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&lt;?php \/** * WGS84\u4e0e\u767e\u5ea6\u5750\u6807\u7cfb (BD-09) \u7684\u8f6c\u6362 * &hellip; <a href=\"http:\/\/www.luwl.net\/?p=1124\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1124","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/www.luwl.net\/index.php?rest_route=\/wp\/v2\/posts\/1124","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.luwl.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.luwl.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.luwl.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.luwl.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1124"}],"version-history":[{"count":2,"href":"http:\/\/www.luwl.net\/index.php?rest_route=\/wp\/v2\/posts\/1124\/revisions"}],"predecessor-version":[{"id":1136,"href":"http:\/\/www.luwl.net\/index.php?rest_route=\/wp\/v2\/posts\/1124\/revisions\/1136"}],"wp:attachment":[{"href":"http:\/\/www.luwl.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.luwl.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1124"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.luwl.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}