2015-10-26 34 views
0

使用SupportMapFragment我可以獲取地圖以顯示並加載到視圖中。然而,這只是它正在做的。我無法獲得它加載點,縮放,或任何有任何價值的東西。Android Google Map(SupportMapFragment)不顯示點

這裏有什麼問題?

我正在使用下面的片段來創建一個SupportMapFragment。

public class MapLocationFragment extends Fragment { 

    public static MapLocationFragment getInstance() 
    { 
     return new MapLocationFragment(); 
    } 

    static final LatLng HAMBURG = new LatLng(53.558, 9.927); 
    static final LatLng KIEL = new LatLng(53.551, 9.993); 
    private GoogleMap map; 

    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 

     View v = inflater.inflate(R.layout.view_map_location_fragment, null, false); 

     map = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map)) 
       .getMap(); 

     Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG) 
       .title("Hamburg")); 
     Marker kiel = map.addMarker(new MarkerOptions() 
       .position(KIEL) 
       .title("Kiel") 
       .snippet("Kiel is cool") 
       .icon(BitmapDescriptorFactory 
         .fromResource(R.drawable.ic_launcher))); 

     map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15)); 
     map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null); 

     return v; 
    } 
} 

我的活動如下所示:

public class MapLocationActivity extends AppCompatActivity { 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 

     super.onCreate(savedInstanceState); 

     setContentView(R.layout.view_map_location); 

     // handle beer venue list 
     MapLocationFragment fragment = MapLocationFragment.getInstance(); 

     getSupportFragmentManager().beginTransaction() 
       .replace(R.id.venueMapSection, fragment) 
       .commit(); 
    } 
} 

回答

0

你需要重寫onMapReady(GoogleMap map)方法。見onMapReady

相關問題