좌표변환 도(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
41
package com.ghj.blog_034;
 
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("=> "+DegreeToDMS(37.49191944444445));
        txtLongitude.setText("=> "+DegreeToDMS(127.56994444444445));
    }
 
    //좌표변환 도(DD) -> 도분초
    public String DegreeToDMS(double degree){
        int hour = (int)degree;
        degree -= hour;
        int minute = (int)(degree*60);
        degree = degree*60 - minute;
        int second = (int)(degree*60);
        degree = degree*60 - second;
        int msecond = (int)(degree*1000);
 
        return hour+":"+minute+"."+second+"/"+msecond;
    }
}
 
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
<?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.49191944444445"
        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" />
 
    <TextView
        android:text="127.56994444444445"
        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>
 
cs



결과


+ Recent posts