我有一个显示良好的 GoogleMap(在 SupportMapFragment 内),并将 GoogleMapOptions 用于目标相机位置。但是,我无法向 GoogleMap 添加标记/折线。下面是创建地图的方法:
private void createMap(List<LatLng> latLngs) {
    if(map == null) {
        GoogleMapOptions options = new GoogleMapOptions();
        mapFragment = SupportMapFragment.newInstance(options);
        map = mapFragment.getMap();
        float zoom = 13;
        CameraPosition cameraP = new CameraPosition(latLngs.get(0), zoom, 0, 0);
        options.camera(cameraP);
        //TODO MAP IS NULL - SORT OUT!
        // check it has been instantiated
        if (map != null) {
            Log.d(TAG, "map is not null");
            map.clear();
            //Calculate target zoom, based on trip size
            map.animateCamera(CameraUpdateFactory
                    .newCameraPosition(cameraP));
            // Add LatLngs to polyline
            PolylineOptions poly = new PolylineOptions().color(Color.RED);
            MarkerOptions startMarker = new MarkerOptions()
                    .position(latLngs.get(0)).title("Start");
            MarkerOptions endMarker = null;
            if(latLngs.size() > 1) {
             endMarker = new MarkerOptions().position(
                    latLngs.get(latLngs.size() - 1)).title("End");  
            }
            for (LatLng latLng : latLngs) {
                poly.add(latLng);
            }
            map.addPolyline(poly);
            map.addMarker(startMarker);
            map.addMarker(endMarker);
        }
        ft = getSupportFragmentManager().beginTransaction();
        ft.add(R.id.trip_summary_map_container, mapFragment);
        ft.commit();
    }
}
正如您从内联注释中看到的那样,地图仍然为空(尽管它正在显示和使用选项)。只是不能添加东西。我假设我没有正确实例化它?
Activity 扩展了 FragmentActivity,我已经设置了使用 Maps API 所需的所有东西。
感谢您的任何帮助。