0

I hope you can help me. My current app is able to get my current location (via GPS). Now I add a marker to my current location which works perfect, but if I want to move my camera to the marker it doesn't work. The inputs for the moveCamera(positon); are the same as for addMarker(position);

here is my code:

//center is used when no location is available (Berlin)
final CameraUpdate center = CameraUpdateFactory.newLatLng(new LatLng(52.5075389,13.5231758)); 
final CameraUpdate zoom = CameraUpdateFactory.zoomTo(14);

//get location from other activity
final Bundle extras = getIntent().getExtras();

MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.mapfragment);
        mapFragment.getMapAsync(new OnMapReadyCallback() {
            @Override
            public void onMapReady(GoogleMap googleMap) {
                LatLng position = new LatLng(52.5075389,13.5231758);

                if (extras != null) { //if location available
                    position = (LatLng)extras.getParcelable("location");
                    final CameraUpdate centerLocation = CameraUpdateFactory.newLatLng(position);

                    MarkerOptions markerOptions = new MarkerOptions().position(position).title(MARKER_TITLE).snippet(MARKER_SNIPPET);
                    googleMap.addMarker(markerOptions);

                    googleMap.getUiSettings().setMapToolbarEnabled(false); //hide auto created buttons
                    googleMap.moveCamera(centerLocation);
                    googleMap.animateCamera(zoom);
                }
    else{
//some other code here
}

My marker is at the correct position, but my centerLocation don't. Any suggestions?

MMG
  • 3,226
  • 5
  • 16
  • 43
CodeIsLaw
  • 307
  • 2
  • 13

1 Answers1

0

thanks to the comments. here is my solution:

final float zoom = 14;

//rest of the code is unchaged

googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(position, zoom));
CodeIsLaw
  • 307
  • 2
  • 13