緯度経度の2点間の距離、角度と座標 - GoogleMap
今回はapache cordovaのGoogleMapのプラグインの話だけど、GoogleMapのAPIならきっと同じように取得できると思われる。計算方法とか調べていたが実際にGoogleMapに表示してみるとけっこうずれたりしてうまくいかなかった。で、プラグインのドキュメント見てたらやりたいことがそのまま機能としてありました。。
GitHub - mapsplugin/cordova-plugin-googlemaps: Google Maps plugin for Cordova
GoogleMapの表示の方法は、READMEみればなんとなくわかるので書かない。
2点間の距離
var spherical = plugin.google.maps.geometry.spherical; var start = { lat: xxx.xxx, lng: xxx.xxx } var end = { lat: xxx.xxx, lng: xxx.xxx } var distance = spherical.computeDistanceBetween(start, end);
2点間の角度
var spherical = plugin.google.maps.geometry.spherical; var start = { lat: xxx.xxx, lng: xxx.xxx } var end = { lat: xxx.xxx, lng: xxx.xxx } var direction = spherical.computeHeading(start, end);
2点間上の任意の座標
var spherical = plugin.google.maps.geometry.spherical; var start = { lat: xxx.xxx, lng: xxx.xxx } var end = { lat: xxx.xxx, lng: xxx.xxx } var direction = spherical.computeHeading(start, end); var distance = xxx; nextLatLng = spherical.computeOffset(start, distance, direction);
GoogleMapすごい。以上です