2点間の距離を取得 – Location.distanceBetween
- Android
-
2014-08-11 - 更新:2014-08-19
この記事は最終更新日から1年以上経過しています。
LocationクラスのdistanceBetweenメソッドを使って、2点間の距離を取得することができます。
書式
Location.distanceBetween(
double startLatitude,
double startLongitude,
double endLatitude,
double endLongitude,
float[] results);
| startLatitude | 開始地点の緯度 |
|---|---|
| startLongitude | 開始地点の経度 |
| endLatitude | 終了地点の緯度 |
| endLongitude | 終了地点の経度 |
| results | 結果を格納する変数 |
| results[0] | 2点間の距離(単位:m) |
|---|---|
| results[1] | 終了地点までの方位角 |
| results[2] | 終了地点からの方位角 |
例)
import android.location.Location;
float[] results = new float[] {};
String distance = "";
try {
Location.distanceBetween(
startLatitude,
startLongitude,
endLatitude,
endLongitude,
results);
if(results != null && results.length > 0) {
distance = String.valueOf((double)results[0]) + "m";
}
} catch (IllegalArgumentException ex) {
}
この記事がお役に立ちましたらシェアお願いします
9,507 views




