티스토리 뷰
Stack Overflow에 자주 검색, 등록되는 문제들과 제가 개발 중 찾아 본 문제들 중에서 나중에도 찾아 볼 것 같은 문제들을 정리하고 있습니다.
Stack Overflow에서 가장 먼저 확인하게 되는 가장 높은 점수를 받은 Solution과 현 시점에 도움이 될 수 있는 가장 최근에 업데이트(최소 점수 확보)된 Solution을 각각 정리하였습니다.
아래 word cloud를 통해 이번 포스팅의 주요 키워드를 미리 확인하세요.
Launching Google Maps Directions via an intent on Android
안드로이드에서 인텐트를 통해 구글 맵스 경로 안내 시작하기
문제 내용
My app needs to show Google Maps directions from A to B, but I don't want to put the Google Maps into my application - instead, I want to launch it using an Intent. Is this possible? If yes, how?
제 앱은 A에서 B까지의 Google Maps 길 안내를 보여주어야 하지만, 앱 내에 Google Maps를 넣고 싶지 않습니다. 대신 Intent를 사용하여 Google Maps를 실행하고 싶습니다. 가능한가요? 가능하다면 어떻게 해야 하나요?
높은 점수를 받은 Solution
You could use something like this:
이런 식으로 사용할 수 있습니다:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=20.344,34.34&daddr=20.5666,45.345"));
startActivity(intent);
To start the navigation from the current location, remove the saddr
parameter and value.
현재 위치에서 내비게이션을 시작하려면 saddr 매개변수와 값을 제거하면 됩니다.
You can use an actual street address instead of latitude and longitude. However this will give the user a dialog to choose between opening it via browser or Google Maps.
위치 정보 대신 실제 주소를 사용할 수도 있습니다. 그러나 이 경우 사용자에게 브라우저나 Google 지도 중에서 선택할 수 있는 대화상자가 제공됩니다.
This will fire up Google Maps in navigation mode directly:
이렇게 하면 Google Maps가 네비게이션 모드로 직접 시작됩니다.
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("google.navigation:q=an+address+city"));
UPDATE
편집
In May 2017 Google launched the new API for universal, cross-platform Google Maps URLs:
2017년 5월, 구글은 플랫폼을 초월한 유니버셜 Google Maps URL을 위한 새로운 API를 출시했습니다.
https://developers.google.com/maps/documentation/urls/guide
You can use Intents with the new API as well.
새 API에서도 Intents를 사용할 수 있습니다.
가장 최근 달린 Solution
to open maps app which is in HUAWEI devices which contains HMS:
HMS(Huawei Mobile Services)를 포함하는 HUAWEI 기기에서 지도 앱을 열려면 다음과 같은 코드를 사용할 수 있습니다.
const val GOOGLE_MAPS_APP = "com.google.android.apps.maps"
const val HUAWEI_MAPS_APP = "com.huawei.maps.app"
fun openMap(lat:Double,lon:Double) {
val packName = if (isHmsOnly(context)) {
HUAWEI_MAPS_APP
} else {
GOOGLE_MAPS_APP
}
val uri = Uri.parse("geo:$lat,$lon?q=$lat,$lon")
val intent = Intent(Intent.ACTION_VIEW, uri)
intent.setPackage(packName);
if (intent.resolveActivity(context.packageManager) != null) {
context.startActivity(intent)
} else {
openMapOptions(lat, lon)
}
}
private fun openMapOptions(lat: Double, lon: Double) {
val intent = Intent(
Intent.ACTION_VIEW,
Uri.parse("geo:$lat,$lon?q=$lat,$lon")
)
context.startActivity(intent)
}
HMS checks:
HMS 체크:
private fun isHmsAvailable(context: Context?): Boolean {
var isAvailable = false
if (null != context) {
val result =
HuaweiApiAvailability.getInstance().isHuaweiMobileServicesAvailable(context)
isAvailable = ConnectionResult.SUCCESS == result
}
return isAvailable}
private fun isGmsAvailable(context: Context?): Boolean {
var isAvailable = false
if (null != context) {
val result: Int = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context)
isAvailable = com.google.android.gms.common.ConnectionResult.SUCCESS == result
}
return isAvailable }
fun isHmsOnly(context: Context?) = isHmsAvailable(context) && !isGmsAvailable(context)
출처 : https://stackoverflow.com/questions/2662531/launching-google-maps-directions-via-an-intent-on-android
'개발 > 안드로이드' 카테고리의 다른 글
XML onClick를 사용하여 Fragment에서 버튼 클릭을 처리하는 방법 (0) | 2022.12.20 |
---|---|
안드로이드에서 전체 화면 액티비티 만들기 (0) | 2022.12.20 |
사용자가 선택하기 전에 Spinner에서 onItemSelected가 실행되지 않게 하는 방법 (0) | 2022.12.19 |
'java.lang.IllegalStateException: Not allowed to start service Intent' 오류 수정하기 (0) | 2022.12.19 |
안드로이드 웹뷰의 캐시 완전히 지우기 (0) | 2022.12.19 |