1

I try to get the accurate location of the user on map but i only received the city name not exact location. Here is the code.

import UIKit
import MapKit
import CoreLocation

class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate
{
@IBOutlet weak var mapView: MKMapView!

let locationManager = CLLocationManager()

override func viewDidLoad()
{
    super.viewDidLoad()

    self.locationManager.delegate = self
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
    self.locationManager.requestWhenInUseAuthorization()
    self.locationManager.startUpdatingLocation()
    self.mapView.showsUserLocation = true

}

override func didReceiveMemoryWarning()
{
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


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

    let location = locations.last! as CLLocation

    let center = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)
    let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 1, longitudeDelta: 1))

    self.mapView.setRegion(region, animated: true)
}

func locationManager(manager: CLLocationManager, didFailWithError error: NSError)
{
    print("Error: " + error.localizedDescription)
}

}

NSLocationWhenInUseUsageDescription add in plist file. Any help. Thankyou

MDaniyal
  • 1,097
  • 3
  • 13
  • 29
fmas
  • 13
  • 4

1 Answers1

0

If you are looking this in simulator. Then follow this process to zoom map. so that you can see streets in map

Press Option/Alt key --> you will see two rounds. pinch it in/out for zoom in/out

Amit Raj Modi
  • 86
  • 1
  • 2
  • Yes, but i want a circle on a current location but its not pointed to the current location. just point the country/ city name. – fmas Mar 25 '16 at 10:48
  • I hope you are looking for this http://stackoverflow.com/questions/9056451/draw-a-circle-of-1000m-radius-around-users-location-in-mkmapview. – Amit Raj Modi Mar 25 '16 at 10:56