2013-03-05 4 views
1

사용자가 텍스트 필드에 주소를 입력하고 버튼을 클릭하면 해당 주소가 Google지도의 대상 필드에 복사되고 사용자 위치가 "내 위치"(현재 위치)로 설정하십시오.구글 맵스 안드로이드의 API

+6

에서 장치/사용자의 현재 위치를 코드는 어디 가야? – yarian

답변

2

Google지도에서 경로를 표시하려면 현재 및 목적지 위도와 경도를 전달하는 인 텐트를 호출하면됩니다. lat-long을 모르면 어떤 경우에도 주소를 전달할 수 있습니다. 이 작업을 수행 한 후 Google지도의 위치를 ​​표시합니다. 스트리트 뷰를 표시 할 수도 있습니다. 당신이 현재의 주소와 목적지 주소가있는 경우 current_lat, current_longi, dest_address

final Intent intent = new Intent(Intent.ACTION_VIEW, 
Uri.parse("http://maps.google.com/maps?" 
+ "saddr="+ current_lat+","+current_longi + "&daddr="+dest_address)); 

intent.setClassName("com.google.android.apps.maps","com.google.android.maps.MapsActivity"); 

startActivity(intent); 

, 다음과 같이 작성할 수 있습니다 :

Uri.parse("http://maps.google.com/maps?" 
+ "saddr="+curr_address+ "&daddr="+dest_address)); 

당신이 현재와 목적지가있는 경우

아래 코드에서

, 세 개의 매개 변수가있다 위도와 경도는 다음과 같이 쓸 수 있습니다.

Uri.parse("http://maps.google.com/maps?" 
+ "saddr="+ current_lat+","+current_longi + "&daddr="+ destt_lat+","+dest_longi )); 

이 인 텐트를 호출하면 Google Map은 버스 또는 도보로 경로를 그릴 지 여부를 표시합니다.

4

당신은 다음과 같은 방법으로 구글 맵을 열 수 있습니다

String CURRENT_LOCATION = "current_location_latitude, current_location_longitude"; 
String DESTINATION_LOCATION = "address_from_your_text_view"; 

Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
Uri.parse("http://maps.google.com/maps?saddr="+ CURRENT_LOCATION +" daddr="+DESTINATION_LOCATION)); 
startActivity(intent); 

참고 : 당신을 locationManager

+0

그것은 매력처럼 작동했습니다! 스택 오버플로는 내가 당신에게 플러스 1을 줄 수 없다. 내가 말할 수있는 것은 고맙다! :) –

+0

back_press에서 위지도 옵션 (지도, 로컬 등 ...)을 표시하지 않으려면 대신 이전 활동을 표시해야합니까 ?? –

+0

키 누르기를 제어 할 수없는 것보다 의도를 통해 애플리케이션/활동에서 Google지도 응용 프로그램을 시작하는 경우 –

관련 문제