Set Location Center of Map - GMaps v2 - Android
Asked Answered
N

2

12

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?

Nonagon answered 2/5, 2013 at 15:41 Comment(0)
N
35

You can try:

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

where map is the GoogleMap instance.

Newport answered 2/5, 2013 at 15:48 Comment(2)
I try this but doesnt really look centered... any ideas to get it exactly on center or my eyes are failing? (i am using animateCamera)Comprehensible
Oh don't worry, there was nothing to fix. The GPS off and some wrong code made it behave weirdly. the code you show does put it exactly centered.Comprehensible
G
0
@Override
public void onMapReady(GoogleMap googleMap) {
    final LatLng SYDNEY = new LatLng(-33.87365, 151.20689);
    googleMap.addMarker(new MarkerOptions().position(SYDNEY));
    googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(SYDNEY, 4.0f));
}
Gorget answered 29/4, 2018 at 9:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.