2013-06-24 2 views
0

가 나는 그것이 그렇다면, 가능하다.) (. FragmentActivty (public class MyGoogleMap extends FragmentActivity { }가, 지금은 조각을 사용하여 구글 맵을 설정하려면 사용 public class MyGoogleMap extends Fragment { }를 구글 맵을 설정하고보다 어떤 생각이 있다면 나와 함께 공유하시기 바랍니다. 감사합니다.Fragment를 사용하여 Android에서 Google지도를 설정하는 방법은 무엇인가요?

+0

https://developers.google.com/maps/documentation/android/ –

+0

예 가능합니다. @DixitPatel에 링크 된 문서에서 제공되는 것 이상을 추가하는 것은 그리 많지 않습니다. 거기에 계단을 따라하십시오. – Rarw

+0

@DixitPatel 나는 당신의 대답을 위해 노력하고 있습니다. –

답변

1

그것은 당신의 XML 레이아웃에 추가 될 예정입니다있는지도에 대한 프레임을 만들기

<RelativeLayout 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:id="@+id/map_container"> 

<!-- The map fragments will go here --> 
</RelativeLayout> 

당신의 조각 클래스 중 하나를 XML의 클래스 = "com.google.android.gms.maps.SupportMapFragment"를 포함하지 마십시오 할 onActivity 안에 수동으로 생성하십시오.

@Override 
public void onActivityCreated(Bundle savedInstanceState) { 
    super.onActivityCreated(savedInstanceState); 
    FragmentManager fm = getChildFragmentManager(); 
    fragment = (SupportMapFragment) fm.findFragmentById(R.id.map_container); 
    if (fragment == null) { 
     fragment = SupportMapFragment.newInstance(); 
     fm.beginTransaction().replace(R.id.map_container, fragment).commit(); 
    } 


/***at this time google play services is not initialized so get map and add what ever you want to it in onResume() or onStart() **/ 
} 

@Override 
    public void onResume() { 
     super.onResume(); 
     if (map == null) { 
      map = fragment.getMap(); 
      map.addMarker(new MarkerOptions().position(new LatLng(0, 0))); 
     } 
} 
관련 문제