Android Google Map (SupportMapFragment) не отображает точки

Используя 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();
    }
}

person aherrick    schedule 26.10.2015    source источник


Ответы (1)


Вам нужно переопределить метод onMapReady(GoogleMap map). См. onMapReady.

person Tasos Moustakas    schedule 26.10.2015