Mapview - Show all of my added Annotations?
Hi, again!
I just implemented a "Things nearby your location" function to my app. I cant determ how to set the zoomlevel - so that all of my annotations are visible in the mapview?
I cant find any documentation regarding "region" and "regionFit"…
Best regards, Joakim
2 Answers
-
You will have to detect the min/max lat/long of all the annotations and set the region to this values
-
Once you know your min and max lats and longs (I calculate mine as I'm looping to add my annotations) you can do something like this which works nicely for me in my app:
//create the map boundary area values var decMapBoundaryLatitude = (decLatitudeMax + decLatitudeMin) / 2; var decMapBoundaryLongitude = (decLongitudeMax + decLongitudeMin) / 2; var decMapBoundaryLatitudeDelta = decLatitudeMax - decLatitudeMin + 0.01; var decMapBoundaryLongitudeDelta = decLongitudeMax - decLongitudeMin + 0.01; //create the map region definition for the boundaries containing the sites var mapRegionSites = {latitude: decMapBoundaryLatitude, longitude: decMapBoundaryLongitude, animate: true, latitudeDelta: decMapBoundaryLatitudeDelta, longitudeDelta: decMapBoundaryLongitudeDelta}; //tell the map view to display the region with the sites in objMapView.setLocation(mapRegionSites);