내 응용 프로그램에서 표준 Google지도 응용 프로그램을 여는 방법은 무엇입니까? 누르면 표준 Google지도 응용

사용자가 내 응용 프로그램에서 버튼을 누르면 표준 Google지도 응용 프로그램을 열고 특정 위치를 표시하고 싶습니다. 내가 어떻게 해? (를 사용하지 않고 com.google.android.maps.MapView)



답변

Intentgeo-URI를 사용하여 객체를 만들어야합니다 .

String uri = String.format(Locale.ENGLISH, "geo:%f,%f", latitude, longitude);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
context.startActivity(intent);

주소를 지정하려면 다른 형식의 geo-URI를 사용해야합니다 geo:0,0?q=address.

참조 : https://developer.android.com/guide/components/intents-common.html#Maps


답변

단순히 http://maps.google.com/maps 를 URI로 사용할 수도 있습니다 .

String uri = "http://maps.google.com/maps?saddr=" + sourceLatitude + "," + sourceLongitude + "&daddr=" + destinationLatitude + "," + destinationLongitude;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);

또는 Google지도 앱만 사용하도록 할 수 있습니다. 이렇게하면 인 텐트 필터 (대화 상자)가 표시되지 않습니다.

intent.setPackage("com.google.android.apps.maps");

이렇게 :

String uri = "http://maps.google.com/maps?saddr=" + sourceLatitude + "," + sourceLongitude + "&daddr=" + destinationLatitude + "," + destinationLongitude;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
intent.setPackage("com.google.android.apps.maps");
startActivity(intent);

또는 다음과 같이 각 좌표 세트 뒤에 괄호 안에 문자열을 추가하여 위치에 레이블을 추가 할 수 있습니다.

String uri = "http://maps.google.com/maps?saddr=" + sourceLatitude + "," + sourceLongitude + "(" + "Home Sweet Home" + ")&daddr=" + destinationLatitude + "," + destinationLongitude + " (" + "Where the party is at" + ")";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
intent.setPackage("com.google.android.apps.maps");
startActivity(intent);

사용자의 현재 위치를 시작점으로 사용하려면 (불행히도 현재 위치에 레이블을 saddr지정할 방법을 찾지 못했습니다) 다음 과 같이 매개 변수를 삭제하십시오 .

String uri = "http://maps.google.com/maps?daddr=" + destinationLatitude + "," + destinationLongitude + " (" + "Where the party is at" + ")";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
intent.setPackage("com.google.android.apps.maps");
startActivity(intent);

완전성을 위해 사용자에게 맵 앱이 설치되어 있지 않으면 @TonyQ 상태와 같이 ActivityNotFoundException을 잡는 것이 좋습니다. 그런 다음 맵 앱 제한없이 활동을 다시 시작할 수 있습니다. 인터넷 브라우저가이 URL 스킴을 시작하기에 유효한 응용 프로그램이기 때문에 결국에는 토스트에 도달하지 않습니다.

        String uri = "http://maps.google.com/maps?daddr=" + 12f + "," + 2f + " (" + "Where the party is at" + ")";
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
        intent.setPackage("com.google.android.apps.maps");
        try
        {
            startActivity(intent);
        }
        catch(ActivityNotFoundException ex)
        {
            try
            {
                Intent unrestrictedIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
                startActivity(unrestrictedIntent);
            }
            catch(ActivityNotFoundException innerEx)
            {
                Toast.makeText(this, "Please install a maps application", Toast.LENGTH_LONG).show();
            }
        }

편집하다:

길 찾기의 경우 탐색 의도가 google.navigation에서 지원됩니다.

Uri navigationIntentUri = Uri.parse("google.navigation:q=" + 12f + "," + 2f);
Intent mapIntent = new Intent(Intent.ACTION_VIEW, navigationIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);

답변

문자열 형식을 사용하면 도움이되지만 로케일을 충분히주의해야합니다. 독일에서는 float 대신 점이 쉼표로 구분됩니다.

사용 String.format("geo:%f,%f",5.1,2.1);로케일 영어 결과에하는 것입니다 "geo:5.1,2.1"하지만, 독일어 로케일 당신은 얻을 것이다"geo:5,1,2,1"

이 동작을 방지하려면 영어 로캘을 사용해야합니다.

String uri = String.format(Locale.ENGLISH, "geo:%f,%f", latitude, longitude);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
context.startActivity(intent);

라벨을 지리적 위치로 설정하려면 다음을 사용하여 지리적 위치를 확장 할 수 있습니다.

!!! 그러나이 점에주의해야합니다. 지리적 위치는 아직 개발 중입니다
http://tools.ietf.org/html/draft-mayrhofer-geo-uri-00

String uri = String.format(Locale.ENGLISH, "geo:%f,%f?z=%d&q=%f,%f (%s)",
                           latitude, longitude, zoom, latitude, longitude, label);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
context.startActivity(intent);

답변

Google에서이 페이지를 확인하십시오.

http://developer.android.com/guide/appendix/g-app-intents.html

양식의 URI를 사용할 수 있습니다

geo:latitude,longitude

Google지도 뷰어를 열고 위치를 가리 킵니다.


답변

geo : protocal과 관련된 응용 프로그램이없는 경우 try-catch를 사용하여 ActivityNotFoundException이 처리하도록 할 수 있습니다.

Google 맵이 기본적으로 설치되지 않은 androVM과 같은 에뮬레이터를 사용할 때 발생합니다.


답변

아래 코드 스 니펫을 사용할 수도 있습니다.이 방법으로 의도가 시작되기 전에 Google지도가 있는지 확인합니다.

Uri gmmIntentUri = Uri.parse(String.format(Locale.ENGLISH,"geo:%f,%f", latitude, longitude));
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
if (mapIntent.resolveActivity(getPackageManager()) != null) {
    startActivity(mapIntent);
}

참조 : https://developers.google.com/maps/documentation/android-api/intents


답변

PIN이있는 위치로 이동하려면 다음을 사용하십시오.

String uri = "http://maps.google.com/maps?q=loc:" + destinationLatitude + "," + destinationLongitude;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
intent.setPackage("com.google.android.apps.maps");
startActivity(intent);

핀이 없으면 URI에서 이것을 사용하십시오.

 String uri = "geo:" + destinationLatitude + "," + destinationLongitude;