2013-04-10 5 views
1

표시된 Google지도에 버튼을 추가하고 싶습니다. 내지도GoogleMap에 버튼을 추가하는 방법

GoogleMap map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); 

내가지도를 표시 할 조각을 사용하여 표시하고 레이아웃 XML은

<fragment xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/map" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      class="com.google.android.gms.maps.SupportMapFragment" /> 

내가보기에 버튼을로드 할 몇 가지 정보를 발견하지만, 그들의 단지 정상이다 Google지도가 아닙니다. 감사합니다.

답변

1

GoogleMap API Reference :

1. 자신의 구현으로 SupportMapFragment 개체를 덮어 쓰기하고 여기에 버튼을 추가를 .

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

     <Button 
      android:id="@+id/bLocateMe" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@drawable/locate_me_button_selector" 
      android:clickable="true" 
      android:onClick="locateMeButtonOnClick" 
      android:text="@string/locate_me" 
      android:textColor="@color/my_white" /> 
    </LinearLayout> 
    <fragment 
     xmlns:map="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/map" 
     android:name="com.google.android.gms.maps.SupportMapFragment" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

</FrameLayout> 
+0

버튼과지도가 동시에로드됩니다. 프로그래밍 방식으로 버튼을로드 할 수 있으므로 시간이되면로드 할 수 있습니다. – Bryanyan

+0

동일한 레이아웃을 사용하고 버튼의 가시성을 보이지 않게 설정 한 다음 필요할 때 가시성을 변경할 수 있습니다. 그렇게하면 당신이 원할 때 나타납니다. –

+0

map = ((SupportMapFragment) getSupportFragmentManager(). findFragmentById (R.id.map)). getMap();을 사용하여 맵을로드합니다. 전체 레이아웃을로드하는 방법? – Bryanyan

0

왜지도에 버튼을 올리시겠습니까? 당신은 당신이 RelativeView에 RelativeView에지도 조각과 장소 버튼을 배치 할 수 있습니다 정적 버튼을 원하는 경우

  1. :

    나는 몇 가지 해결책이있다.

  2. 그렇지 않으면지도와 함께 이동하는 버튼이 필요하면지도에 몇 가지 모양을 추가 할 수 있습니다. 예를 들어 addCircle 메서드를 사용하고 setOnMapClickListener를 사용하여지도의 클릭을 처리합니다. 보기 당신은 몇 가지 옵션이 있습니다, 그래서 당신은 Google지도 객체에 직접 버튼을 추가 할 수 없습니다
+0

그렇다면, 어떻게 정적 표시 할 수 있습니다

2 쉬운 옵션은 예를 들어, FrameLayout 내부 fragment을 설정하고, 직접 LinearLayout 또는를 사용하여이 FrameLayout에 단추를 추가하는 것입니다 본문? 프로그래밍 방식으로 텍스트 뷰를 추가 할 수 있습니까? 필요한 경우 textview로드하고 싶습니다. – Bryanyan

+0

이렇게하려면 Paint 객체를 사용하여 원하는 텍스트의 비트 맵을 만든 다음 해당 비트 맵을 아이콘이나 이미지로 사용하여 googlemap에 마커/그라운드 오버레이를 배치해야합니다. –

관련 문제