Android: GoogleMaps v2 - Set location/position of map or animate/slide to a location

Much like integrating the GoogleMaps v2 library into your Android app, programmatically moving the camera around isn't as straight forward either.

The first thing you'll need is a target location. The second is a CameraPosition.

LatLng target = new LatLng(lat, lng);
CameraPosition cameraPosition = new CameraPosition.Builder();
.zoom(15)
.target(target)
.build();

This will set up a camera with zoom level 15 (mostly street level) and centered around the given target location.

At this point you can also set up the camera rotation and tilt as well with bearing() and tilt(). Try values of 90 and 30 respectively to see what they do.

Now to get a handle to your map.

SupportMapFragment supportMapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
googleMap = supportMapFragment.getMap();

Finally, you can position the GoogleMap instance.

googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

That'll animate/slide the camera to the given position. If you want to move it without animation, then use moveCamera() instead.

ios6
Time to get busy mapping!

Sources

 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog