{"id":8633,"date":"2021-11-11T09:09:45","date_gmt":"2021-11-11T01:09:45","guid":{"rendered":"https:\/\/sdeno.com\/?p=8633"},"modified":"2024-09-02T11:48:24","modified_gmt":"2024-09-02T03:48:24","slug":"jsshixiangenjuliangdianweizhidejingweiduhuoqujuli","status":"publish","type":"post","link":"https:\/\/sdeno.com\/?p=8633","title":{"rendered":"JS\u5b9e\u73b0\u6839\u636e\u4e24\u70b9\u4f4d\u7f6e\u7684\u7ecf\u7eac\u5ea6\u83b7\u53d6\u8ddd\u79bb"},"content":{"rendered":"<p>\u5750\u6807 \u8ddd\u79bb \u5750\u6807 \u7ecf\u7eac\u5ea6 \u8ddd\u79bb<\/p>\n<pre>\/\/ \u7ecf\u7eac\u5ea6\u8f6c\u6362\u6210\u4e09\u89d2\u51fd\u6570\u4e2d\u5ea6\u5206\u8868\u5f62\u5f0f\u3002\r\n        function rad(d) {\r\n            return d * Math.PI \/ 180.0; \r\n        }\r\n\r\n\r\n        \/\/ \u6839\u636e\u7ecf\u7eac\u5ea6\u8ba1\u7b97\u8ddd\u79bb\uff0c\u53c2\u6570\u5206\u522b\u4e3a\u7b2c\u4e00\u70b9\u7684\u7eac\u5ea6\uff0c\u7ecf\u5ea6\uff1b\u7b2c\u4e8c\u70b9\u7684\u7eac\u5ea6\uff0c\u7ecf\u5ea6\r\n        function getDistance(lat1, lng1, lat2, lng2) {\r\n\r\n            var radLat1 = rad(lat1);\r\n            var radLat2 = rad(lat2);\r\n            var a = radLat1 - radLat2;\r\n            var b = rad(lng1) - rad(lng2);\r\n            var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a \/ 2), 2) +\r\n                Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b \/ 2), 2)));\r\n            s = s * 6378.137; \/\/ EARTH_RADIUS;\r\n            s = Math.round(s * 10000) \/ 10000; \/\/\u8f93\u51fa\u4e3a\u516c\u91cc\r\n\r\n            var distance = s;\r\n            var distance_str = \"\";\r\n\r\n            if (parseInt(distance) &gt;= 1) {\r\n                distance_str = distance.toFixed(1) + \"km\";\r\n            } else {\r\n                distance_str = distance * 1000 + \"m\";\r\n            }\r\n\r\n            \/\/s=s.toFixed(4);\r\n\r\n            console.info('lyj \u8ddd\u79bb\u662f', s);\r\n            console.info('lyj \u8ddd\u79bb\u662f', distance_str);\r\n            return s;\r\n        }\r\n    \r\n        \/\/\u8c03\u7528\uff0c\u6ca1\u6709\u5148\u540e\u4e4b\u5206\uff0c\u4f46\u662f\u7ecf\u7eac\u5ea6\u5fc5\u987b\u662f\u540c\u4e00\u4e2a\u5730\u70b9\r\n        getDistance(lat1, lng1, lat2, lng2)<\/pre>\n<p>&nbsp;<\/p>\n<p>\u83b7\u53d6\u7ecf\u7eac\u5ea6\uff1a<a href=\"https:\/\/lbs.amap.com\/tools\/picker\" target=\"_blank\" rel=\"noopener\">https:\/\/lbs.amap.com\/tools\/picker<\/a><\/p>\n<p>\u83b7\u53d6\u7ecf\u7eac\u5ea6\uff0c\u53ca\u4e24\u70b9\u8ddd\u79bb\u6848\u4f8b\uff1a<a href=\"https:\/\/developer.amap.com\/demo\/jsapi-v2\/example\/calcutation\/calculate-distance-between-two-markers\" target=\"_blank\" rel=\"noopener\">https:\/\/developer.amap.com\/demo\/jsapi-v2\/example\/calcutation\/calculate-distance-between-two-markers<\/a><\/p>\n<p><a href=\"https:\/\/www.cnblogs.com\/feiquan\/p\/11338691.html\" target=\"_blank\" rel=\"noopener\">https:\/\/www.cnblogs.com\/feiquan\/p\/11338691.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5750\u6807 \u8ddd\u79bb \u5750\u6807 \u7ecf\u7eac\u5ea6 \u8ddd\u79bb \/\/ \u7ecf\u7eac\u5ea6\u8f6c\u6362\u6210\u4e09\u89d2\u51fd\u6570\u4e2d\u5ea6\u5206\u8868\u5f62\u5f0f\u3002 function rad(d) {  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-8633","post","type-post","status-publish","format-standard","hentry","category-11"],"_links":{"self":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/8633","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8633"}],"version-history":[{"count":2,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/8633\/revisions"}],"predecessor-version":[{"id":9834,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/8633\/revisions\/9834"}],"wp:attachment":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8633"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8633"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8633"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}