Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MapKit default zoom

Tags:

swift

mapkit

For some reason my market won't zoom to the local region. In fact, it does not change the zoom no matter what I change. Am I loading it in the wrong part of the code, or am I missing something else? Any help is appreciated.

My code is:

@IBOutlet var here: MKMapView!

var locationManager: CLLocationManager?
var selectedItem: String?
func locationManager
    (manager: CLLocationManager!,didUpdateToLocation newLocation: CLLocation!,
    fromLocation oldLocation: CLLocation!){
        manager.desiredAccuracy = kCLLocationAccuracyBest


        var region = self.here.region as MKCoordinateRegion

        self.here.setRegion(region, animated: true)
        region.span.longitudeDelta = 0.0144927536
        region.span.latitudeDelta = 0.0144927536

}
like image 395
Andy Dewan Avatar asked Feb 03 '15 00:02

Andy Dewan


People also ask

How do you get zoom level in Mkmapview?

The easiest way to get an Integer of the current zoom level, is by using the MapView function: regionDidChangeAnimated. This function recognizes every change in zoom and will give you the basis for the calculation of the zoom factor.

How do I zoom in on mapView?

MKCoordinateRegion zoomIn = mapView. region; zoomIn. span. latitudeDelta *= 0.5; [mapView setRegion:zoomIn animated:YES];

What is MapKit in IOS?

Overview. Use MapKit to give your app a sense of place with maps and location information. You can use the MapKit framework to: Embed maps directly into your app's windows and views. Add annotations and overlays to a map to call out points of interest.


1 Answers

I believe you need to set the lat and long BEFORE you set the region. The setRegion function is what zooms in on a certain part, and the level of the zoom depends on your span. Here's an example of a map that zooms.

let span = MKCoordinateSpanMake(0.075, 0.075)
let region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: lat, longitude: long), span: span)
mapView.setRegion(region, animated: true)
like image 131
leerob Avatar answered Oct 08 '22 18:10

leerob