{"id":3998,"date":"2017-09-25T11:05:56","date_gmt":"2017-09-25T03:05:56","guid":{"rendered":"http:\/\/blog.hoyo.idv.tw\/?p=3998"},"modified":"2018-07-24T10:13:59","modified_gmt":"2018-07-24T02:13:59","slug":"%e4%bd%bf%e7%94%a8-php-%e8%a8%88%e7%ae%97-wgs84-%e5%ba%a7%e6%a8%99%e5%85%a9%e9%bb%9e%e4%b9%8b%e9%96%93%e7%9a%84%e8%b7%9d%e9%9b%a2","status":"publish","type":"post","link":"https:\/\/blog.hoyo.idv.tw\/?p=3998","title":{"rendered":"\u4f7f\u7528 PHP \u8a08\u7b97 WGS84 \u5ea7\u6a19\u5169\u9ede\u4e4b\u9593\u7684\u8ddd\u96e2"},"content":{"rendered":"<p>\u53c3\u8003<\/p>\n<ul>\n<li><a href=\"https:\/\/my.oschina.net\/ekc\/blog\/84106\" target=\"_blank\" rel=\"noopener noreferrer\">php \u6839\u636e\u4e24\u70b9\u7684\u7ecf\u7eac\u5ea6\u8ba1\u7b97\u8ddd\u79bb<\/a><\/li>\n<li><a href=\"https:\/\/support.google.com\/maps\/answer\/18539?co=GENIE.Platform%3DDesktop&amp;hl=zh-Hant\" target=\"_blank\" rel=\"noopener noreferrer\">\u627e\u51fa\u6216\u8f38\u5165\u7d93\u7def\u5ea6<\/a><br \/>\n\u5ea6\u6578\u3001\u5206\u6578\u548c\u79d2\u6578 (DMS)\uff1a41\u00b024'12.2\"N 2\u00b010'26.5\"E<br \/>\n\u5ea6\u6578\u548c\u5c0f\u6578\u5206\u6578 (DMM)\uff1a41 24.2028, 2 10.4418<br \/>\n\u5341\u9032\u4f4d\u5ea6\u6578 (DD)\uff1a41.40338, 2.17403<\/li>\n<li>Android \u53ef\u4ee5\u4e0b\u8f09\u300c\u5730\u5716\u5ea7\u6a19\u300d\u986f\u793a\u6240\u5728\u5ea7\u6a19<\/li>\n<\/ul>\n<p>--<\/p>\n<h2>\u5be6\u969b\u6e2c\u8a66<\/h2>\n<p>\u5f9e\u00a022.9957173, 120.1746395 \u5230\u00a022.9961966, 120.1747138 \u7684\u8ddd\u96e2\uff0cGoogle Map \u6e2c\u91cf\u70ba 54 \u516c\u5c3a<\/p>\n<p><a href=\"http:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2017\/09\/Image-273.png\" target=\"_blank\" rel=\"noopener noreferrer\" data-rel=\"lightbox-image-0\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" class=\"alignnone wp-image-3999 size-medium\" src=\"http:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2017\/09\/Image-273-300x131.png\" alt=\"\" width=\"300\" height=\"131\" srcset=\"https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2017\/09\/Image-273-300x131.png 300w, https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2017\/09\/Image-273-768x335.png 768w, https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2017\/09\/Image-273-1024x446.png 1024w, https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2017\/09\/Image-273-500x218.png 500w, https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2017\/09\/Image-273.png 1060w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>\u4f7f\u7528 PHP \u7a0b\u5f0f<\/p>\n<pre class=\"lang:php decode:true \">&lt;?php\r\n\r\nfunction getDistance($lat1, $lng1, $lat2, $lng2)\r\n{\r\n    $earthRadius = 6367000; \/\/approximate radius of earth in meters\r\n\r\n    $lat1 = ($lat1 * pi() ) \/ 180;\r\n    $lng1 = ($lng1 * pi() ) \/ 180;\r\n\r\n    $lat2 = ($lat2 * pi() ) \/ 180;\r\n    $lng2 = ($lng2 * pi() ) \/ 180;\r\n    \r\n    $calcLongitude = $lng2 - $lng1;\r\n    $calcLatitude = $lat2 - $lat1;\r\n    $stepOne = pow(sin($calcLatitude \/ 2), 2) + cos($lat1) * cos($lat2) * pow(sin($calcLongitude \/ 2), 2);  $stepTwo = 2 * asin(min(1, sqrt($stepOne)));\r\n    $calculatedDistance = $earthRadius * $stepTwo;\r\n\r\n    return round($calculatedDistance);\r\n}\r\n\r\necho getDistance(22.9957173, 120.1746395, 22.9961966, 120.1747138);\r\n<\/pre>\n<p>\u7d50\u679c\u4e5f\u662f 54 \uff0c\u6240\u4ee5\u6b64\u7a0b\u5f0f\u8a08\u7b97\u70ba\u6b63\u78ba\u8ddd\u96e2<\/p>\n<p>--<\/p>\n<p>&nbsp;<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"3998\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;2,851&nbsp;total views<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u53c3\u8003 php \u6839\u636e\u4e24\u70b9\u7684\u7ecf\u7eac\u5ea6...<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"3998\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;2,851&nbsp;total views<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[260],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/3998"}],"collection":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3998"}],"version-history":[{"count":4,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/3998\/revisions"}],"predecessor-version":[{"id":4761,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/3998\/revisions\/4761"}],"wp:attachment":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3998"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3998"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3998"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}