{"id":2995,"date":"2013-08-14T10:37:32","date_gmt":"2013-08-14T01:37:32","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=2995"},"modified":"2013-12-30T21:43:25","modified_gmt":"2013-12-30T12:43:25","slug":"post-2995","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/node-js\/2995","title":{"rendered":"JavaScript\u3067\u8ddd\u96e2\u8a08\u7b97\u306a\u3069\u5730\u7406\u60c5\u5831\u51e6\u7406\u3092\u884c\u3046\u30e9\u30a4\u30d6\u30e9\u30ea\u300cGeolib\u300d"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/08\/geolib-e1376444094697.jpg\" alt=\"geolib\" width=\"590\" height=\"234\" class=\"aligncenter border size-full wp-image-2996\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/08\/geolib-e1376444094697.jpg 590w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/08\/geolib-e1376444094697-300x119.jpg 300w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><\/p>\n<p>\u7def\u5ea6\u7d4c\u5ea6\u306e\u30c7\u30fc\u30bf\u304b\u3089\u3001\uff12\u70b9\u9593\u306e\u8ddd\u96e2\u3092\u6c42\u3081\u305f\u308a\u3001\u4e2d\u5fc3\u70b9\u306e\u7b97\u51fa\u306a\u3069\u304c\u884c\u3048\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\u3002<\/p>\n<p><a href=\"https:\/\/github.com\/manuelbieh\/Geolib\">Geolib<\/a><\/p>\n<p>100%pureJavascript\u3067\u66f8\u304b\u308c\u3066\u3044\u308b\u306e\u3067\u3001node.js\u3067\u3082\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u3067\u3082\u4f7f\u7528\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>node.js\u3067\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u65b9\u6cd5\u306f\u4ee5\u4e0b\u3002<\/p>\n<pre class=\"lang:js decode:true \" >npm install geolib\n<\/pre>\n<h2>\u30b5\u30f3\u30d7\u30eb<\/h2>\n<p>\u7fa4\u99ac\u306e\u5730\u7406\u306b\u8a73\u3057\u304f\u306a\u3044\u3068\u3088\u304f\u308f\u304b\u3089\u306a\u3044\u30b5\u30f3\u30d7\u30eb\u3002<\/p>\n<pre class=\"lang:js decode:true \" >var geolib = require('geolib');\n\n\/\/\uff12\u70b9\u9593\u306e\u8ddd\u96e2\u3092\u6c42\u3081\u308b\nvar distance = geolib.getDistance(\n    {latitude: 36.322356, longitude: 139.013057},\t\/\/\u9ad8\u5d0e\u99c5\n    {latitude: 36.383191, longitude: 139.073177}\t\/\/\u524d\u6a4b\u99c5\n);\nconsole.log(distance+&quot;m&quot;); \/\/-&gt;8642m\n\n\n\n\/\/\u30b3\u30f3\u30d0\u30fc\u30c8\nconsole.log(geolib.convertUnit('km', distance) + &quot;km&quot;); \/\/-&gt;8.642km\nconsole.log(geolib.convertUnit('mi', distance) + &quot;mi&quot;); \/\/-&gt;5.3699\u30de\u30a4\u30eb\nconsole.log(geolib.convertUnit('ft', distance) + &quot;ft&quot;); \/\/-&gt;28353.0184\u30d5\u30a3\u30fc\u30c8\n\n\n\n\/\/\u4e2d\u5fc3\u70b9\u3092\u6c42\u3081\u308b\nvar center = geolib.getCenter([\n    {latitude: 36.322356, longitude: 139.013057},\t\/\/\u9ad8\u5d0e\u99c5\n    {latitude: 36.383191, longitude: 139.073177},\t\/\/\u524d\u6a4b\u99c5\n    {latitude: 36.41107600000001, longitude: 139.333037},\t\/\/\u6850\u751f\u99c5\n    {latitude: 36.294066, longitude: 139.378734},\t\/\/\u592a\u7530\u99c5\n    {latitude: 36.250183, longitude: 139.08331599999997},\t\/\/\u85e4\u5ca1\u99c5\n\t\n]);\nconsole.log(center); \/\/-&gt;{ latitude: '36.330630', longitude: '139.195896', distance: 37.373 }\n\n\n\n\/\/\u542b\u307e\u308c\u308b\u304b\u306e\u5224\u5b9a\nvar isInside1 = geolib.isPointInside(\n    {latitude: 36.32668100000001, longitude: 139.19382500000006},\t\/\/\u4f0a\u52e2\u5d0e\u99c5\n    [\n        {latitude: 36.322356, longitude: 139.013057},\t\/\/\u9ad8\u5d0e\u99c5\n        {latitude: 36.383191, longitude: 139.073177},\t\/\/\u524d\u6a4b\u99c5\n        {latitude: 36.41107600000001, longitude: 139.333037},\t\/\/\u6850\u751f\u99c5\n        {latitude: 36.294066, longitude: 139.378734},\t\/\/\u592a\u7530\u99c5\n        {latitude: 36.250183, longitude: 139.08331599999997},\t\/\/\u85e4\u5ca1\u99c5\n    ]\n); \nconsole.log(isInside1); \/\/-&gt;True\n\nvar isInside2 = geolib.isPointInside(\n    {latitude: 36.490693, longitude: 139.00841100000002},\t\/\/\u6e0b\u5ddd\u99c5\n    [\n        {latitude: 36.322356, longitude: 139.013057},\t\/\/\u9ad8\u5d0e\u99c5\n        {latitude: 36.383191, longitude: 139.073177},\t\/\/\u524d\u6a4b\u99c5\n        {latitude: 36.41107600000001, longitude: 139.333037},\t\/\/\u6850\u751f\u99c5\n        {latitude: 36.294066, longitude: 139.378734},\t\/\/\u592a\u7530\u99c5\n        {latitude: 36.250183, longitude: 139.08331599999997},\t\/\/\u85e4\u5ca1\u99c5\n    ]\n); \nconsole.log(isInside2); \/\/-&gt;False\n\n\n\n\/\/\u5186\u5185\u306b\u542b\u307e\u308c\u308b\u304b\u306e\u5224\u5b9a\nvar inCircle = geolib.isPointInCircle(\n    {latitude: 36.322356, longitude: 139.013057},\t\/\/\u9ad8\u5d0e\u99c5 \/\/\u5224\u5225\u5bfe\u8c61\n    {latitude: 36.383191, longitude: 139.073177},\t\/\/\u524d\u6a4b\u99c5 \/\/circle\u306e\u4e2d\u5fc3\u70b9\n    10000 \/\/\u534a\u5f84(m)\n);\nconsole.log(inCircle); \/\/-&gt;True\n\n\n\n\/\/\u8ddd\u96e2\u304c\u8fd1\u3044\u9806\u306b\u4e26\u3079\u66ff\u3048\nvar distanceList = geolib.orderByDistance(\n    {latitude: 36.322356, longitude: 139.013057},\t\/\/\u9ad8\u5d0e\u99c5\n\t[\n\t\t{latitude: 36.383191, longitude: 139.073177},\t\/\/\u524d\u6a4b\u99c5\n\t\t{latitude: 36.41107600000001, longitude: 139.333037},\t\/\/\u6850\u751f\u99c5\n\t\t{latitude: 36.294066, longitude: 139.378734},\t\/\/\u592a\u7530\u99c5\n\t\t{latitude: 36.250183, longitude: 139.08331599999997},\t\/\/\u85e4\u5ca1\u99c5\n\t]\n);\nconsole.log(distanceList);\n\/* -&gt;\n[ { key: '0',\n    latitude: 36.383191,\t\/\/\u524d\u6a4b\u99c5\n    longitude: 139.073177\n    distance: 8642 },\n  { key: '3',\n    latitude: 36.250183,\t\/\/\u85e4\u5ca1\u99c5\n    longitude: 139.083315\n    distance: 10197 },\n  { key: '1',\n    latitude: 36.41107600\t\/\/\u6850\u751f\u99c5\n    longitude: 139.333037\n    distance: 30357 },\n  { key: '2',\n    latitude: 36.294066,\t\/\/\u592a\u7530\u99c5\n    longitude: 139.378734\n    distance: 32992 } ]\n*\/\n\n\n\n\/\/\u4e00\u756a\u8fd1\u3044\u30dd\u30a4\u30f3\u30c8\u3092\u62bd\u51fa\nvar near = geolib.findNearest(\n    {latitude: 36.322356, longitude: 139.013057},\t\/\/\u9ad8\u5d0e\u99c5\n\t[\n\t\t{latitude: 36.383191, longitude: 139.073177},\t\/\/\u524d\u6a4b\u99c5\n\t\t{latitude: 36.41107600000001, longitude: 139.333037},\t\/\/\u6850\u751f\u99c5\n\t\t{latitude: 36.294066, longitude: 139.378734},\t\/\/\u592a\u7530\u99c5\n\t\t{latitude: 36.250183, longitude: 139.08331599999997},\t\/\/\u85e4\u5ca1\u99c5\n\t]\n);\nconsole.log(near); \/\/-&gt; { key: '0', latitude: 36.383191, longitude: 139.073177, distance: 8642 } \/\/\u524d\u6a4b\u99c5<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7def\u5ea6\u7d4c\u5ea6\u306e\u30c7\u30fc\u30bf\u304b\u3089\u3001\uff12\u70b9\u9593\u306e\u8ddd\u96e2\u3092\u6c42\u3081\u305f\u308a\u3001\u4e2d\u5fc3&hellip;<\/p>\n","protected":false},"author":1,"featured_media":2996,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,5],"tags":[],"class_list":["post-2995","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","category-node-js","has-post-thumbnail-archive"],"_links":{"self":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/2995","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/comments?post=2995"}],"version-history":[{"count":0,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/2995\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/2996"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=2995"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=2995"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=2995"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}