http://developer.android.com/google/play-services/maps.html
구글맵을 써야했는데, 샘플을 받아서 하면 에러나서 그냥 새로 만들었다.
activity에서 호출할 때는 괜찮았는데, fragment 를 상속받은 클래스에서는 SupportMapFragment 를 쓸 수가 없더라.
<fragment android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" class="com.google.android.gms.maps.SupportMapFragment" />
이래저래 검색해보니 SupportMapFragment를 MapFragment로 바꿔서 써보라고 한다.
<fragment android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" class="com.google.android.gms.maps.MapFragment" />
뭔지 기억은 안나는데, 그래도 뭔가가 안 좋았다.
또 찾아보니 이번엔 괜찮은 방법이 나왔다.
import com.google.android.gms.maps.GoogleMap; public class WalkFragment extends Fragment { private GoogleMap _map; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_walk, container, false); MapView mapView = (MapView) view.findViewById(R.id.map); mapView.onCreate(savedInstanceState); mapView.onResume(); try { MapsInitializer.initialize(getActivity().getApplicationContext()); } catch (Exception e) { e.printStackTrace(); } _map = mapView.getMap(); } }
이렇게하니까 잘 된다.