좌표의 몇 m거리의 위도, 경도 구하기



java)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.ghj.blog_035;
 
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
 
public class MainActivity extends AppCompatActivity {
 
    //UI
    TextView txtLatitude;
    TextView txtLongitude;
 
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        //UI
        txtLatitude = (TextView)findViewById(R.id.txtLatitude);
        txtLongitude = (TextView)findViewById(R.id.txtLongitude);
 
 
        double diffLatitude = LatitudeInDifference(500);
        double diffLongitude = LongitudeInDifference(37.51937500);
 
        txtLatitude.setText((37.51937-diffLatitude)+" ~ "+(37.51937+diffLatitude));
        txtLongitude.setText((126.940114-diffLongitude)+" ~ "+(126.940114+diffLongitude));
    }
 
 
    //반경 m이내의 위도차(degree)
    public double LatitudeInDifference(int diff){
        //지구반지름
        final int earth = 6371000;    //단위m
 
        return (diff*360.0/ (2*Math.PI*earth);
    }
 
    //반경 m이내의 경도차(degree)
    public double LongitudeInDifference(double _latitude, int diff){
        //지구반지름
        final int earth = 6371000;    //단위m
 
        double ddd = Math.cos(0);
        double ddf = Math.cos(Math.toRadians(_latitude));
 
        return (diff*360.0/ (2*Math.PI*earth*Math.cos(Math.toRadians(_latitude)));
    }
}
 
cs



xml)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
 
    <TextView
        android:text="좌표 (37.519378, 126.940114)의 500m 거리의 위도, 경도 구하기"
        android:textSize="24dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
 
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:text="위도 : "
            android:textSize="24dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <TextView
            android:id="@+id/txtLatitude"
            android:textSize="24dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>
 
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:text="경도 : "
            android:textSize="24dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <TextView
            android:id="@+id/txtLongitude"
            android:textSize="24dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>
 
</LinearLayout>
 
cs



결과

구한 위도, 경도내의 좌표를 구한후 두 좌표사이의 거리를 구하여 한번 더 걸러내야 한다.


+ Recent posts