Map keep bounce back while I try to zoom in

Hello swift newbie was here. I working on map application and I have problem with region span. I change it to 0.05,0.05 and I want it to be zoom in and out. Then find out when I move around latitude&longitude will change. That make my map keep bounce back to 0.05 span here my code.

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

    let latispan = 0.05
    let longspan = 0.05

    let location = locations.last
    let center = CLLocationCoordinate2D(latitude: location!.coordinate.latitude, longitude: location!.coordinate.longitude)
    let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: latispan, longitudeDelta: longspan))
    self.mapView.setRegion(region, animated: true)
    //labelText.text = "\(location!.coordinate.latitude) , \(location!.coordinate.longitude)"

    labelText.text = "\(region.span.latitudeDelta), \(region.span.longitudeDelta)"
    //self.locationManager.stopUpdatingLocation()
}
func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
    print("Errors:" + error.localizedDescription)
}

I try to get current span so I might change my latispan, longspan later, but I just can't find a way.

Upvotes: 0

Views: 305

Answers (1)

Himali Shah
Himali Shah

Reputation: 189

Try Following this may help you :)

func loadMapData() {

        if let location = AppDelegate.getInstance().newlocation {
            let center = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)
            let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05))
            self.map.setRegion(region, animated: true)
        }

        self.map.removeAnnotations(self.map.annotations)
        self.map.showsUserLocation = true
        for retailer in self.liststores {
            let information = MKPointAnnotation()
            information.coordinate = CLLocationCoordinate2D(latitude: retailer.retailer_lat!.doubleValue, longitude: retailer.retailer_lon!.doubleValue)
            information.title = retailer.retailer_name
            information.subtitle = retailer.retailer_addr1! + retailer.retailer_addr2!
            self.map.addAnnotation(information)
        }
    }

Upvotes: 1

Related Questions