Google maps api v2 zooming near the marker
Asked Answered
R

2

26

I am using Google maps api v2 in android. I have placed a marker by using latitude and longitude . The marker is shown at correct place , but i want the the map should show area around the marker only .i.e i want to zoom to markers position when the map is shown so it shows nearby region of the marker only..any help would be great.

Reeba answered 9/5, 2013 at 9:48 Comment(0)
H
78

pass your current location in this function where you have placed your marker.

private void moveToCurrentLocation(LatLng currentLocation)
{   
    googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(currentLocation,15));
    // Zoom in, animating the camera.
    googleMap.animateCamera(CameraUpdateFactory.zoomIn());
    // Zoom out to zoom level 10, animating with a duration of 2 seconds.
    googleMap.animateCamera(CameraUpdateFactory.zoomTo(15), 2000, null);


}
Heptagon answered 9/5, 2013 at 9:51 Comment(2)
@ Arsal Imam I glad it helped..:)Heptagon
nice work bro... if you can please explain last 2 animation camera more..Unready
C
22

Provide marker position.

private void pointToPosition(LatLng position) {
    //Build camera position
    CameraPosition cameraPosition = new CameraPosition.Builder()
            .target(position)
            .zoom(17).build();
    //Zoom in and animate the camera.
    mGoogleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
Cottier answered 9/7, 2015 at 6:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.