java)

package com.ghj.blog_036;

 

import android.location.Location;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.widget.TextView;

 

public class MainActivity extends AppCompatActivity {

 

    //UI

    TextView txtJava;

    TextView txtAndroid;

 

 

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

 

        //UI

        txtJava = (TextView)findViewById(R.id.txtJava);

        txtAndroid = (TextView)findViewById(R.id.txtAndroid);

 

        txtJava.setText(DistanceByDegree(37.476780, 126.981429, 37.504445, 127.049317)+"m");

        txtAndroid.setText(DistanceByDegreeAndroid(37.476780, 126.981429, 37.504445, 127.049317)+"m");

    }

 

    //두지점(위도,경도) 사이의 거리

    public double DistanceByDegree(double _latitude1, double _longitude1, double _latitude2, double _longitude2){

        double theta, dist;

        theta = _longitude1 - _longitude2;

        dist = Math.sin(DegreeToRadian(_latitude1)) * Math.sin(DegreeToRadian(_latitude2)) + Math.cos(DegreeToRadian(_latitude1))

                * Math.cos(DegreeToRadian(_latitude2)) * Math.cos(DegreeToRadian(theta));

        dist = Math.acos(dist);

        dist = RadianToDegree(dist);

 

        dist = dist * 60 * 1.1515;

        dist = dist * 1.609344;    // 단위 mile 에서 km 변환.

        dist = dist * 1000.0;      // 단위  km 에서 m 로 변환

 

        return dist;

    }

 

    //안드로이드 - 두지점(위도,경도) 사이의 거리

    public double DistanceByDegreeAndroid(double _latitude1, double _longitude1, double _latitude2, double _longitude2){

        Location startPos = new Location("PointA");

        Location endPos = new Location("PointB");

 

        startPos.setLatitude(_latitude1);

        startPos.setLongitude(_longitude1);

        endPos.setLatitude(_latitude2);

        endPos.setLongitude(_longitude2);

 

        double distance = startPos.distanceTo(endPos);

 

        return distance;

    }

 

    //degree->radian 변환

    public double DegreeToRadian(double degree){

        return degree * Math.PI / 180.0;

    }

 

    //randian -> degree 변환

    public double RadianToDegree(double radian){

        return radian * 180d / Math.PI;

    }

}

 

 

xml)

<?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.476780, 126.981429) 와 (37.504445, 127.049317) 사이의 거리"

        android:textSize="24dp"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content" />

 

    <TextView

        android:id="@+id/txtJava"

        android:textSize="24dp"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content" />

 

    <TextView

        android:id="@+id/txtAndroid"

        android:textSize="24dp"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content" />

</LinearLayout>

 

 

 

 

결과

두 API 사이에 차이가 있다

Screenshot_2016-11-18-07-25-56.png

 

번호 제목 글쓴이 날짜 조회 수
128 PC를 위한 최고의 안드로이드 에뮬레이터 황제낙엽 2023.01.18 3132
127 [Jetpack Compose UI / 상추님] GDG Jetpack compose 코드랩 수료 후기 (feat. 굿즈) 황제낙엽 2022.12.24 2370
126 [Jetpack Compose UI / kyj1991719] compose - Compose 이해 황제낙엽 2022.12.24 4025
125 [Jetpack Compose UI / 꾸준] Compose 가 뭔데...? 황제낙엽 2022.12.24 4035
124 [Jetpack Compose UI / IIVIKI] Compose 학습과 분석 황제낙엽 2022.12.24 4050
123 [Jetpack Compose UI] 스터디 시작하기 황제낙엽 2022.12.24 4001
122 [개발하는 정대리] 취준생을 위한 안드로이드 앱만들기 - 바텀네비게이션 뷰, 네비게이션 AAC file 황제낙엽 2022.12.22 3882
121 [개발하는 정대리] 취준생을 위한 안드로이드 앱만들기 - 뷰바인딩 file 황제낙엽 2022.12.22 3850
120 [개발하는 정대리] 취준생을 위한 안드로이드 앱만들기 - 라이브데이터 뷰모델 file 황제낙엽 2022.12.21 3826
119 [대왕놀] ImageButton in Compose (IconButton) 황제낙엽 2022.12.20 4105
118 [대왕놀] compose instrumentation test tutorial 황제낙엽 2022.12.20 3985
117 [대왕놀] Switch in Compose 황제낙엽 2022.12.20 4106
116 [대왕놀] EditText in Compose (TextField) 황제낙엽 2022.12.20 4021
115 [대왕놀] margin in Compose 황제낙엽 2022.12.20 4105
114 [대왕놀] modifier in compose 황제낙엽 2022.12.20 4180
113 [대왕놀] Button in Compose file 황제낙엽 2022.12.20 4224
112 [대왕놀] TextView in Compose (Text) 황제낙엽 2022.12.20 4083
111 [대왕놀] ImageView in Compose (Image) 황제낙엽 2022.12.20 4017
110 [대왕놀] LinearLayout in Compose (Row, Column) 황제낙엽 2022.12.20 4113
109 [대왕놀] Introduction to Jetpack compose 황제낙엽 2022.12.20 3964