반응형
myLoc에서 targetLoc까지의 거리를 구한다.
반환값은 float로 단위는 m이다.
// 좌표로 거리구하기
fun getDistance( lat1: Double, lng1:Double, lat2:Double, lng2:Double) : Float{
val myLoc = Location(LocationManager.NETWORK_PROVIDER)
val targetLoc = Location(LocationManager.NETWORK_PROVIDER)
myLoc.latitude= lat1
myLoc.longitude = lng1
targetLoc.latitude= lat2
targetLoc.longitude = lng2
return myLoc.distanceTo(targetLoc)
}
반응형
'IT > Android' 카테고리의 다른 글
안드로이드 스튜디오] 파일명이 빨간색으로 나타날 때 (0) | 2020.12.18 |
---|---|
Kotlin] 안드로이드 스튜디오 AsyncTask ProgressDialog (2) | 2020.08.17 |
Kotlin] 안드로이드 스튜디오 인터넷 연결 상태 확인 (0) | 2020.08.08 |
Kotlin] 안드로이드 스튜디오 AlertDialog 위치 (0) | 2020.08.08 |
안드로이드 앱] 그래픽 이미지 생성기 (0) | 2020.06.14 |
댓글