좌표변환 도(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 |
결과
'IT > - 프로그래밍' 카테고리의 다른 글
안드로이드 두지점(위도,경도) 사이의 거리 (0) | 2016.11.18 |
---|---|
안드로이드 좌표의 몇 m거리의 위도, 경도 구하기 (0) | 2016.11.17 |
안드로이드 좌표변환 도분초를 도(degree)로 변환 (0) | 2016.11.15 |
안드로이드 Assets폴더에서 파일 읽어오기 (0) | 2016.11.14 |
안드로이드 앱 최초 실행여부 확인하기 (1) | 2016.11.13 |