LoginSignup
19
16

More than 5 years have passed since last update.

位置情報の座標系から南北東西で指定した距離の座標を得る方法

Last updated at Posted at 2016-10-26

位置(lat,lon)から南北nkm、東西nkm離れた地点の座標を得る関数

Android Javaでサンプルを載せます。
経度が緯度により1度あたりの長さが変わりますので、その辺を求めたら四則演算で済ませます。
ソース中LatLngはgoogle map apiのクラスですが、latlonをバラバラに保持するのがめんどいので使ってるだけですので適当に読み替えてください。


package com.example.y_hoshi.maptest.com.example.y_hoshi.maptest.util;

import com.google.android.gms.maps.model.LatLng;

/**
 * GeocodeingUtil
 *
 * 位置情報系の便利関数クラス
 * Created by y_hoshi on 2016/10/26.
 */

public class GeocodeingUtil {
    public static final double DISTANCE_ONE_DEGREE_LATITUDE = 111.3194908;
    public static final double RADIAN_COEFFICIENT = 0.017453293;

    /**
     * 経度1度あたりの距離(km)を返す
     * @param latiudeDegree 距離を求める座標の緯度
     * @return 経度1度あたりの距離(km)
     */
    public static double getDistanceOneDegreeLongitude(double latiudeDegree){
        double res = Math.cos(latiudeDegree * RADIAN_COEFFICIENT) * DISTANCE_ONE_DEGREE_LATITUDE;
        return res;
    }

    /**
     * 指定した座標から南北方向及び東西方向で指定した距離(km)分ずらした座標を返す
     * @param here 現在座標
     * @param toSN 南北方向の移動距離(緯度の正方向を正数、逆を負数で)
     * @param toEW 東西方向の移動距離(経度の正方向を正数、逆を負数で)
     * @return 新しい座標
     */
    public static LatLng getAwayCoordinate(LatLng here, double toSN, double toEW){
        double distanceOneLongitude = GeocodeingUtil.getDistanceOneDegreeLongitude(here.latitude);

        double addLatitudeDegree = toSN / DISTANCE_ONE_DEGREE_LATITUDE;
        double addLongitudeDegree = toEW / distanceOneLongitude;

        return new LatLng(here.latitude + addLatitudeDegree, here.longitude + addLongitudeDegree);
    }
}

一応googleのplace picker起動のサンプルも置いておきます。
渋谷駅を中心に600m四方のピッカーを起動するサンプル

PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
builder.setLatLngBounds(
        new LatLngBounds(GeocodeingUtil.getAwayCoordinate(
                new LatLng(35.658100,139.701742), -0.3d, -0.3d)
                ,GeocodeingUtil.getAwayCoordinate(
                new LatLng(35.658100,139.701742),0.3d,0.3d)
        )
);
try {
    startActivityForResult(builder.build((Activity)MainActivity.this), PLACE_PICKER_REQUEST);
} catch (GooglePlayServicesRepairableException e) {
    e.printStackTrace();
} catch (GooglePlayServicesNotAvailableException e) {
    e.printStackTrace();
}

結果

こんなんが指定座標を中心としたnkm範囲で起動できる

19
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
16