좌표변환 도분초를 도(degree)로 변환



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
package com.ghj.blog_033;
 
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);
 
        //도분초 -> 도로 좌표변환
        txtLatitude.setText("=> "+DMSToDegree("37:29.30/910"));
        txtLongitude.setText("=> "+DMSToDegree("127:34.11/800"));
    }
 
 
    //좌표변환 도분초(::/) -> 도(DD)
    public double DMSToDegree(String dms){
        String[] cordinates = dms.split("[:|.|/]");
        int dmsDo = Integer.parseInt(cordinates[0]);
        int dmsMinute = Integer.parseInt(cordinates[1]);
        int dmsSecond = Integer.parseInt(cordinates[2]);
        int dmsMSecond = Integer.parseInt(cordinates[3]);
 
        return dmsDo+dmsMinute/60.0+dmsSecond/3600.0+dmsMSecond/3600.0/1000.0;
    }
}
 
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
<?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">
 
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:text="37:29.30/910"
            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="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:text="127:34.11/800"
            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