2013-09-26 6 views
0

나는이 문제에 대해 이미 많은 주제를 읽었지만 아무런 도움도주지 못했다. 그래서 SupportMapFragment의 Google지도에서 작업하고 싶습니다. FragmentActivity에서 나는 내에서 MapFragment의 코드가 정확히android (Support) MapFragment getMap() return null

public class MapFragment extends SupportMapFragment { 

private final String TAG = getClass().getSimpleName(); 


public View onCreateView(LayoutInflater inflater, ViewGroup container, 
     Bundle savedInstanceState) { 
    return inflater.inflate(R.layout.map, null); 
} 

public void onActivityCreated(Bundle savedInstanceState) { 
    super.onActivityCreated(savedInstanceState); 
} 

@Override 
public void onViewCreated(View view, Bundle savedInstanceState) { 
    super.onViewCreated(view, savedInstanceState); 

    GoogleMap gMap = this.getMap(); 

    Log.d(TAG, 
      "getMap() " + ((gMap == null) ? "null" : gMap.toString())); 

    // Setting Location and Zoom 
    gMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(
      40.76793169992044f, -73.98180484771729f), 14.0f)); 
} 

} 

나는하여 getMap 방법 ... 어떤 아이디어로 널 얻고마다처럼 보이는에서 onCreate 방법

@Override 
public void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.content_frame); 

    // Initialize Google Maps Android API 
    try { 
     MapsInitializer.initialize(this); 
    } catch (GooglePlayServicesNotAvailableException e) { 
     e.printStackTrace(); 
    } 
... 

의지도를 초기화?

€의 DIT : 최신 버전으로 구글 플레이 서비스를 업데이트 한 후, 비슷한 문제에 직면

<?xml version="1.0" encoding="utf-8"?> 
<fragment xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:map="http://schemas.android.com/apk/res-auto" 
android:id="@+id/map" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
class="com.google.android.gms.maps.SupportMapFragment" 
map:cameraBearing="112.5" 
map:cameraTargetLat="-33.796923" 
map:cameraTargetLng="150.922433" 
map:cameraTilt="30" 
map:cameraZoom="50" 
map:mapType="normal" 
map:uiCompass="false" 
map:uiRotateGestures="true" 
map:uiScrollGestures="false" 
map:uiTiltGestures="true" 
map:uiZoomControls="false" 
map:uiZoomGestures="true" /> 
+1

에 메타 데이터를 추가하여 레이아웃의지도가 해결되었습니다 ? – njzk2

+0

직접적으로. 조각 파일 layoutfile이 있습니다. 편집 된 게시물에서 확인하십시오. – Forke

+1

getMap() 코드를 onStart 또는 onResume으로 옮겨 보았습니까? 내 대답을 참조하십시오 http://stackoverflow.com/a/20747717/2364687, 귀하의 경우에는 적용되지 않을 수도 있습니다. 또한 Google Play 서비스가 설치되어 있어야합니다 (예 : onCreate에서 예외를 포착하고 무시하지 않음). – GLee

답변