Adam Adam - 1 year ago 99
iOS Question

User Location Finder

I've got an button that when it is pressed it goes to users location. Can't figure out what to put in so I can get the zoom on the users location.

The following code I put in my button.

@IBAction func Refreshbutton(sender: AnyObject) {
Mapview.setCenterCoordinate(Mapview.userLocation.coordinate, animated: true)

Answer Source

this is how I do it in Swift:

   @IBAction func CenterMapToUserLocation(sender: AnyObject) {
        let latitude = locationManager.location?.coordinate.latitude
        let longitude = locationManager.location?.coordinate.longitude
        let span = MKCoordinateSpanMake(0.02, 0.02)
        let region = MKCoordinateRegion(center:CLLocationCoordinate2D(latitude: latitude!, longitude: longitude!),span: span)
        tripMapView.setRegion(region, animated: true)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download