Reputation: 785
I have my map view which currently follows the user location however, I want to set the amount it is zoomed in to show a 2km radius from the users location.
My question is how would you do this, is there a zoom function? Or do I need to work out distance from the location and set a corresponding coordinates/region.
How help is great as I'm extremely new to swift! Thanks in advance
Upvotes: 3
Views: 1138
Reputation: 290
Apple Swift Documentation from MKMapView
When you initialize a map view, you should specify the initial region for that map to display. You do this by setting the region property of the map. A region is defined by a center point and a horizontal and vertical distance, referred to as the span. The span defines how much of the map at the given point should be visible and is also how you set the zoom level. Specifying a large span results in the user seeing a wide geographical area and corresponds to a low zoom level. Specifying a small span results in the user seeing a more narrow geographical area and corresponds to a higher zoom level.
So you have to set the region and the span value.
var span = MKCoordinateSpanMake(0.02, 0.02)
var region = MKCoordinateRegion(center:CLLocationCoordinate2D(latitude:
lat, longitude: long),span: span)
mapView.setRegion(region, animated: true)
I suggest you should follow the update of the didUpdateLocationFunction and set the fresh location value to the lat and long variable. The tracking mode not guarantee constant zoom level.
Upvotes: 2