Set Location Center of Map - GMaps v2 - Android

user268397 picture user268397 · May 2, 2013 · Viewed 18k times · Source

How do I set the center of the map to a specific location using GMaps v2? This is how I did it using GMaps v1:

public void setCenter( LatLng point )
{
  if( point.latitude*1000000 != 0 && point.longitude*1000000 != 0 )
  {
     if( mMapController != null )
     {
        mMapController.setCenter( point );
     }
     /*else if( mOpenStreetMapViewControllerSource != null )
     {
        mOpenStreetMapViewControllerSource.getController().setCenter( new org.osmdroid.util.GeoPoint( point.getLatitudeE6(), point.getLongitudeE6() ) );
        mPostponedSetCenterPoint = point;
     }*/
  }
}

I have looked through the API for GMaps v2 and can't find and similar functionality. How do I do this?

Answer

Brtle picture Brtle · May 2, 2013

You can try:

map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude, longitude), zoom));

where map is the GoogleMap instance.