ActionBar.NAVIGATION_MODE_TABS가있는 레이아웃이 있습니다. 첫 번째 탭은 결과를 listview에 표시하고 두 번째 탭은지도에 표시합니다. 최신 버전의 Google Play 서비스 라이브러리로 업그레이드 할 때까지 모든 것이 잘 작동했습니다. 여기Google지도를 조각화하는 방법은 무엇인가요?
지도를 표시하는 데 사용되는 조각 :
public class PlaceMapFragment extends Fragment {
MapView mapView;
GoogleMap map;
ResultsListener mCallback;
List<Place> places;
private HashMap<String, Place> placeMarker = new HashMap<String, Place>();
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
places = mCallback.getPlaces();
View rootView = inflater.inflate(R.layout.mapview, container, false);
mapView = (MapView) rootView.findViewById(R.id.mapview);
mapView.onCreate(savedInstanceState);
map = mapView.getMap();
setUpMap();
return rootView;
}
private void setUpMap() {
map.getUiSettings().setMyLocationButtonEnabled(true);
map.setMyLocationEnabled(true);
/*
try {
MapsInitializer.initialize(this.getActivity());
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
*/
// add markers
}
@Override
public void onResume() {
mapView.onResume();
super.onResume();
setUpMap();
}
@Override
public void onPause() {
mapView.onPause();
super.onPause();
}
@Override
public void onDestroy() {
mapView.onDestroy();
super.onDestroy();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
public interface ResultsListener {
public List<Place> getPlaces();
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
// This makes sure that the container activity has implemented
// the callback interface. If not, it throws an exception
try {
mCallback = (ResultsListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString() + " must implement ResultsListener");
}
}
}
나는 이러한 오류를 얻을 : GooglePlayServicesNotAvailableException
오류를 제공하기 때문에 나는 MapsInitializer.initialize(this.getActivity());
부분을 댓글을 달았
04-05 03:58:22.040: E/AndroidRuntime(661): FATAL EXCEPTION: main
04-05 03:58:22.040: E/AndroidRuntime(661): java.lang.NullPointerException
04-05 03:58:22.040: E/AndroidRuntime(661): at com.tomsyweb.mapslee.fragments.PlaceMapFragment.setUpMap(PlaceMapFragment.java:54)
04-05 03:58:22.040: E/AndroidRuntime(661): at com.tomsyweb.mapslee.fragments.PlaceMapFragment.onCreateView(PlaceMapFragment.java:48)
. 장치가 다른 이유로 아마 설치지도의 최신 버전을 사용하지 않는 경우, 또는
mapview.xml
<com.google.android.gms.maps.MapView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
내 코드는 null도 가능 Getting Google Map Fragment in onCreateView using ActionBar tabs
내 대답을보십시오 : 그래서이 같은
initMap()
방법을 만들고,onCreate(...)
및onResume()
당신에 전화를 권장합니다. – GrIsHu