Reputation: 885
As title, in map v1 i could use
mapController.zoomToSpan(..., ..., ...);
to include all markers on the screen.
Dose map V2 has the same method?
2013/2/22 edit:
first, get all LatLng points you want to involve on the screen.
Assume if you have 3 LatLng points, use
LatLngBounds bounds = new LatLngBounds.Builder().include(point1)
.include(point2).include(point3).build();
mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 50));
Upvotes: 15
Views: 3051
Reputation: 3073
Fews methods of Google map V2 can do the same things :
static CameraUpdate newLatLngBounds(LatLngBounds bounds, int padding)
Returns a CameraUpdate that transforms the camera such that the specified latitude/longitude bounds are centered on screen at the greatest possible zoom level.
static CameraUpdate newLatLngBounds(LatLngBounds bounds, int width, int height, int padding)
Returns a CameraUpdate that transforms the camera such that the specified latitude/longitude bounds are centered on screen within a bounding box of specified dimensions at the greatest possible zoom level.
static CameraUpdate newLatLngZoom(LatLng latLng, float zoom)
Returns a CameraUpdate that moves the center of the screen to a latitude and longitude specified by a LatLng object, and moves to the given zoom level.
Here is an example to use one of them :
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(geoPoint, zoom));
Upvotes: 0
Reputation: 91
Try This
map.addMarker(new MarkerOptions().position(latlng)).setVisible(true);
// Move the camera instantly to location with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, 15));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(14), 2000, null);
Upvotes: 2
Reputation: 1992
map V2
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
GoogleMap map = ((SupportMapFragment)getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
if (map != null) {
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(12), 2000, null);
}
}
you can change the value of 12, that is the zooming level of map load. Have fun!
Upvotes: 0
Reputation: 2464
I hope this will be use full to you.
public class GoogleMapActivity extends FragmentActivity {
private GoogleMap map;
Bundle extras;
LatLng latlng;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.google);
extras = getIntent().getExtras();
if (extras != null) {
unit_long = extras.getString("unit_long");
unit_lat = extras.getString("unit_lat");
}
latlng = new LatLng(Double.parseDouble("19.25252"),
Double.parseDouble("23.25252525"));
map = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
Marker hamburg = map.addMarker(new MarkerOptions().position(latlng)
.title("Location").snippet("I am here")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker)));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, 15));
// Zoom in, animating the camera.use this line in your code
map.animateCamera(CameraUpdateFactory.zoomTo(14), 2000, null);
// map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
}
}
Upvotes: 0