sitelink1 http://ghj1001020.tistory.com/301 
sitelink2  
sitelink3  

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 단말기 고유값 구하는 방법들 황제낙엽 2019.03.03 11910
127 저장소 파일 불러올 때 권한 요청 설정 file 황제낙엽 2018.08.21 3021
126 icudtl.dat (Microsoft Office Access 2010 14를 위해 Microsoft가 생성한 Dynamic Link Library) 황제낙엽 2021.07.07 2135
125 Emulator: audio: Failed to create voice `adc' 황제낙엽 2018.08.06 1911
124 뷰 캡처하여 이미지 파일로 저장하기(화면 캡처)-04 file 황제낙엽 2018.08.12 1839
123 고유 식별자의 모범 사례 (Android Developers) 황제낙엽 2019.03.03 1266
122 뷰 캡처하여 이미지 파일로 저장하기(화면 캡처)-06 file 황제낙엽 2018.08.19 1148
121 HTTP 프로토콜을 이용한 Json Post 보내고 받기 file 황제낙엽 2017.08.03 942
120 Error:Execution failed for task ':app:lintVitalRelease'. 황제낙엽 2018.01.29 937
119 파일 입출력(내장 메모리, 외장메모리) 황제낙엽 2018.08.19 866
118 STT 학습 링크 모음 (sample link) 황제낙엽 2018.10.11 797
117 HttpURLConnection 에서 세션 유지하기(쿠키 사용) 황제낙엽 2017.08.03 796
116 Image to byte Array (바로 사용가능한 JPEG 파일) 황제낙엽 2018.07.24 777
115 [성공샘플] HttpURLConnection 을 이용하여 JSON 데이터 보내기 예제 황제낙엽 2018.11.10 770
114 ABI 관리 황제낙엽 2017.03.28 655
113 TTS 를 위한 스마트폰 설정 및 TTS 샘플 file 황제낙엽 2019.02.16 605
112 안드로이드 스튜디오(Android Studio) 최적화 file 황제낙엽 2018.02.07 589
111 android.webkit.CookieManager 를 이용한 웹뷰와의 세션 공유 황제낙엽 2019.04.26 511
110 동적 레이아웃 생성과 자동 줄바꿈 구현 file 황제낙엽 2018.12.26 460
109 Kotlin의 기본 문법 황제낙엽 2022.11.04 433