I need to zoom out my map. I have tried --mMapView.zoomout();-- but it only zoom out 1 level, I want to zoom out further. I know can do in .xml --mapoptions.ZoomLevel="5"-- but I wanted to put in my Activity Class. Some guides is needed, thank you very much.
MapOptions option = new MapOptions(MapOptions.MapType type);
// Sets zoom level.
option.setZoom(int zoom);
// Switches basemap by the given options.
mMapView.setMapOptions(MapOptions options);
I think, Best way to handle zoom with animation,Even, it will work nice if you add any other layer like "One Map".
/* set zoom level */
double LEVEL=5;
mMapView.centerAt(lat, lng, false);
mMapView.setScale(ZOOM_LEVEL, true);
if you want to show current location with proper Zooming use below code
mMapView.getLocationDisplayManager().setAutoPanMode(LocationDisplayManager.AutoPanMode.LOCATION);
mMapView.getLocationDisplayManager().start();
Related
I am trying to change the zoom level when I click on my Location button but it is always getting default zoom value.
Guess what, the zoom doesn't work only in Animate part. If I use moveCamera it changes the zoom level to what I have specified.
Here is what I am trying:
googleMap.setOnMyLocationButtonClickListener(new OnMyLocationButtonClickListener()
{
#Override
public boolean onMyLocationButtonClick()
{
Log.e("Inside","Click part");
LatLng ll = new LatLng(curlat,curlong);
CameraUpdate update = CameraUpdateFactory.newLatLngZoom(ll, 20);
googleMap.animateCamera(update);
return false;
}
});
Not sure what is wrong here in the animate part?
You should return true instead of false. Otherwise the map performs the default action in addition, which most probably (I did not check in detail) includes to move to the current position (same as your ll) but using the "current" zoom level. The current zoom level has not yet changed much, if you animate the camera. But it has changed completely if you move the camera directly without animation.
I have an app that uses a Google Map Fragment and i want to set somehow a limit to the zoom level that the user can get to by using the +/- icons provided in the map fragment.
Is there any known way to do this?
MY SOLUTION:
private final GoogleMap.OnCameraChangeListener mOnCameraChangeListener =
new GoogleMap.OnCameraChangeListener() {
#Override
public void onCameraChange(CameraPosition cameraPosition) {
Log.d("Zoom", "Zoon: " + cameraPosition.zoom);
if (cameraPosition.zoom > 16.01) {
getMap().animateCamera(CameraUpdateFactory.zoomTo(16));
}
}
};
in onViewCreated() :
//set the zoom limit
getMap().setOnCameraChangeListener(mOnCameraChangeListener);
So far this is showing me the zoom level each time the zoom level changes. i am not sure how i can limit the zoom here though... i can't just do cameraPosition.zoom=15 since it's a final variable.
Any suggestions highly appreciated.
You cannot limit zoom as of version 4.0.30 of the API.
There is a pending feature request for that here: https://code.google.com/p/gmaps-api-issues/issues/detail?id=4663
If you cannot wait, you can try to implement something like this: http://youtube.com/watch?v=-nCZ37HdheY
This uses OnCameraChangeListener and GoogleMap.animateCamera.
You can remove the zoom buttons and use your own, where you have more control. Then, you can disable buttons as needed based upon business rules.
We all know that some of the predefined landmarks on Google Maps does not appear on a lower zoom level, but on a higher zoom level, it suddenly appears. I would like to know If I can make a customized marker not appear at lower zoom levels, then appear at higher ones.
EDIT: Here is a snippet of my code.
// Changing marker icon
marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.gasbig));
// adding marker
map.addMarker(marker);
//position on Center
CameraPosition cameraPosition = new CameraPosition.Builder().target(
new LatLng(14.635356, 121.03272914)).zoom(16).build();
map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
map.setOnCameraChangeListener(new OnCameraChangeListener() {
#Override
public void onCameraChange(CameraPosition arg0) {
if(arg0.zoom > 7){
marker.visible(true);
}
}
});
I tried the suggestion of MaciejGórski but the marker still appears on all zoom levels. I'm sorry about the question I'm still an android newbie.
Thanks in advance.
You can do that for any Marker you want: call setVisible in OnCameraChangeListener.onCameraChange callback with true or false depending on CameraPosition.zoom value.
Edit after question edit:
You need to keep a reference to Marker instead of MarkerOptions:
// adding marker
marker = map.addMarker(markerOptions);
and call setVisible on that marker:
#Override
public void onCameraChange(CameraPosition cameraPosition) {
marker.setVisible(cameraPosition.zoom > 7);
}
Note: setVisible is always called there, but this might not be optimal when using many Markers.
You could possibly do it by modifying my answer to: Android Maps v2 - animate camera to include most markers
Otherwise using Android Maps Extensions might be a good choice. No experince with your specific needs though.
Just realized I might have misunderstood the question. Thought you meant your own markers. Nevertheless have a look at the extensions library. Could very well be that they have something useful.
I'm drawing a lot of markers on the map and when they located close they overlap each other. So I want to hide some markers on small zoom and show more markers when user zooming map. Like more zoom in, more markes. Here is example code of activity and creating of markers, as you can see I'm using google maps android api v2:
public class MainActivity extends FragmentActivity
{
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GoogleMap map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
map.getUiSettings().setMyLocationButtonEnabled(true);
createMarkers(map);
}
private void createMarkers(GoogleMap map) {
double initLat = 48.462740;
double initLng = 35.039572;
for(float i = 0; i < 2; i+=0.2) {
LatLng pos = new LatLng(initLat + i,initLng);
map.addMarker(new MarkerOptions()
.position(pos)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));
}
for(float i = 0; i < 2; i+=0.2) {
LatLng pos = new LatLng(initLat, initLng + i);
map.addMarker(new MarkerOptions()
.position(pos)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));
}
}
It sounds like typical task for me, but i still didn't manage to find working solution. I've read this article https://developers.google.com/maps/articles/toomanymarkers but I've no idea how to implement it on android. Does anybody has some working code which can do this?
Here is my solution to this problem: https://github.com/Bersh/MarkersCluster
Maybe it's not the best solution, but it works for me. Hope it'll be usefull.
You are basically asking how to implement clustering on Android. As far as I know, there is no solution provided by Google to do this. The document you referenced in the comments (developers.google.com/maps/articles/toomanymarkers) is referring to the google maps javascript API. Unfortunately, none of the clustering related code is yet available on Android.
You will have to come up with your own algorithm to cluster Markers. The developers.google.com/maps/articles/toomanymarkers document that you pointed to may be a good starting point to decide what algorithm will work best for you (grid based clustering, distance based clustering, etc).
Another option that's slightly easier to implement (but not perfect) might be to change the Marker image to a smaller icon when the zoom level has changed so they don't overlap as much. Check out my answer to this question: https://stackoverflow.com/a/13976080/1103584
You could use that answer to determine when you've crossed a "zoom threshold" and change the Markers to something smaller once you've zoomed out passed a certain threshold and to a bigger image when you've zoomed back in. I use this trick in a couple of my own apps to change regular icons to small dot images when zoomed out, and back to the regular icon when you zoom back in.
I want to zoom in or out of the map depending on where markers on my map are placed. The markers are dynamic so I can not chose a static zoom level. I understand that there is 'zoomToRegion' method in iOS to acheive this. Is there something similar in Android?
Yes.
You have to use the method zoomToSpan of MapController.
// zoom into map to box of results
int centerLat = (int)(((maxLat-minLat)/2+ minLat)*1E6);
int centerLon = (int)(((maxLon-minLon)/2 + minLon)*1E6);
mapView.getController().animateTo(new GeoPoint( centerLat, centerLon));
mapView.getController().zoomToSpan((int)((maxLat-minLat)*1E6), (int)((maxLon-minLon)*1E6));