Created a function but in an if statement the function isn't recognized swift - ios

I made the function getLocation() and used it in an else{ getLocation()} which works. Later when I tried to define a new function locationmanager the if...{ getLocation()} gets the error:
Use of unresolved identifier 'getLocation'
I'm not sure if the syntax isn't right or if there's another way to call on the getLocation function.
import UIKit
import MapKit
class ViewController: UIViewController, CLLocationManagerDelegate {
var coreLocationManager = CLLocationManager()
var locationManager: LocationManager!
#IBOutlet weak var mapView: MKMapView!
#IBOutlet weak var location_info: UILabel!
#IBAction func Update_Location(_ sender: Any) {
}
override func viewDidLoad() {
super.viewDidLoad()
coreLocationManager.delegate=self
locationManager = LocationManager.sharedInstance
let authorizationCode = CLLocationManager.authorizationStatus()
if authorizationCode == CLAuthorizationStatus.notDetermined &&
coreLocationManager.responds(to: #selector(CLLocationManager.requestWhenInUseAuthorization))||coreLocationManager.responds(to: #selector(CLLocationManager.requestAlwaysAuthorization)){}
if Bundle.main.object(forInfoDictionaryKey: "NSlocationWhenInUseUsageDescription") != nil{
coreLocationManager.requestWhenInUseAuthorization()
}else{
getLocation()
}
}
func getLocation(){
locationManager.startUpdatingLocationWithCompletionHandler{(latitude, longitude, status, verboseMessage, error)->()in
self.displayLocation(location: CLLocation(latitude: latitude, longitude: longitude))
}
}
func displayLocation(location:CLLocation){
mapView.setRegion(MKCoordinateRegion(center: CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longitude),span: MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05)), animated:true)
let locationPinCoord = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)
let annotation = MKPointAnnotation()
annotation.coordinate = locationPinCoord
mapView.addAnnotation(annotation)
mapView.showAnnotations([annotation], animated: true)
locationManager.reverseGeocodeLocationWithCoordinates(location) { (reverseGecodeInfo, placemark, error) in
print(reverseGecodeInfo!)
}
}
}
func locationmanager(manager: CLLocationManager!, didChangeAuthorizationStatus status: CLAuthorizationStatus){
if status != CLAuthorizationStatus.notDetermined || status != CLAuthorizationStatus.denied || status != CLAuthorizationStatus.restricted {
getLocation()
}
}

Do yourself a favor and use proper indentation.
Try this, select-all, cut, then paste. Xcode will auto indent for you and you will immediately see that the problem is that you have a } in the wrong place.

Related

How can I show my current location in maps in Xcode?

I watched a few lessons on Youtube and now tried to get hands-on experience. I am pursuing a little project which involves a tabbed app where I tried on the first page to create a map with a button showing the current location. Pretty basic actually. But somehow it just doesn’t work and I don’t know what’s the issue. Someone from CodewithChris told me this “I would suggest breaking up your app into smaller components and making sure each one works before going on to the next. Try outputting your location first before plotting it on a map etc so you can localize bugs easier.” I just don’t understand what she means by smaller components. I really appreciate all the help I can get. Below is the code as good as possible. Thanks in advance for your help.
import UIKit
import MapKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate, MKMapViewDelegate {
#IBOutlet var textFieldForAddress: UITextField!
#IBOutlet var getDirectionsButton: UIButton!
#IBOutlet var map: MKMapView!
var locationManger = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
locationManger.delegate = self
locationManger.desiredAccuracy = kCLLocationAccuracyBest
locationManger.requestAlwaysAuthorization()
locationManger.requestWhenInUseAuthorization()
locationManger.startUpdatingLocation()
map.delegate = self
}
#IBAction func getDirectionsTapped(_ sender: Any) {
getAddress()
}
func getAddress() {
let geoCoder = CLGeocoder()
geoCoder.geocodeAddressString(textFieldForAddress.text!) { (placemarks, error) in
guard let placemarks = placemarks, let location = placemarks.first?.location
else {
print("No Location Found")
return
}
print(location)
self.mapThis(destinationCord: location.coordinate)
}
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
print(locations)
}
func mapThis(destinationCord : CLLocationCoordinate2D) {
let souceCordinate = (locationManger.location?.coordinate)!
let soucePlaceMark = MKPlacemark(coordinate: souceCordinate)
let destPlaceMark = MKPlacemark(coordinate: destinationCord)
let sourceItem = MKMapItem(placemark: soucePlaceMark)
let destItem = MKMapItem(placemark: destPlaceMark)
let destinationRequest = MKDirections.Request()
destinationRequest.source = sourceItem
destinationRequest.destination = destItem
destinationRequest.transportType = .automobile
destinationRequest.requestsAlternateRoutes = true
let directions = MKDirections(request: destinationRequest)
directions.calculate { (response, error) in
guard let response = response else {
if let error = error {
print("Something is wrong :(")
}
return
}
let route = response.routes[0]
self.map.addOverlay(route.polyline)
self.map.setVisibleMapRect(route.polyline.boundingMapRect, animated: true)
}
}
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
let render = MKPolylineRenderer(overlay: overlay as! MKPolyline)
render.strokeColor = .blue
return render
}
}
If you want to show the user location and have the map track it, you need to set two properties on the map view - showsUserLocation and userTrackingMode. In order for the map to have access to the user location you must receive whenInUse authorisation from the user, using CLocationManager.
import MapKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate, MKMapViewDelegate {
#IBOutlet var textFieldForAddress: UITextField!
#IBOutlet var getDirectionsButton: UIButton!
#IBOutlet var map: MKMapView!
var locationManger = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
locationManger.requestWhenInUseAuthorization()
map.showsUserLocation = true
map.userTrackingMode = .follow
}
If you are running on the simulator then you need to simulate a location using the Debug menu in the simulator.
Okay, this information is surprising hard to find (just getting your own location!) — even after watching tutorials I had a hard time. But basically what you're missing is mapView.showsUserLocation = true
Here's the full code, if you need it...
import UIKit
import CoreLocation
import MapKit
class RadiusMapLocationViewController: UIViewController, MKMapViewDelegate {
#IBOutlet weak var mapView: MKMapView!
let coordinate = CLLocationCoordinate2DMake(33.97823607957177, -118.43823725357653)
var locationManager : CLLocationManager = CLLocationManager()
// Authorize use of location
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
mapView.showsUserLocation = (status == .authorizedAlways)
}
// Entering region
func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion) {
showAlert(withTitle: "You've entered \(region.identifier)", message: "Happy hopping!")
}
// Exiting region
func locationManager(_ manager: CLLocationManager, didExitRegion region: CLRegion) {
showAlert(withTitle: "You've exited \(region.identifier)", message: "")
}
// Creating region and notifying when exit / enter
func region(with geotification: Geotification) -> CLCircularRegion {
let region = CLCircularRegion(center: geotification.coordinate,
radius: geotification.radius,
identifier: geotification.identifier)
region.notifyOnEntry = (geotification.eventType == .onEntry)
region.notifyOnExit = !region.notifyOnEntry
return region
}
// Monitoring region, if not "error"
func startMonitoring(geotification: Geotification) {
if !CLLocationManager.isMonitoringAvailable(for: CLCircularRegion.self) {
showAlert(withTitle:"Error", message: "Geofencing is not supported on this device!")
return
}
}
func stopMonitoring(geotification: Geotification) {
for region in locationManager.monitoredRegions {
guard let circularRegion = region as? CLCircularRegion,
circularRegion.identifier == geotification.identifier else { continue }
locationManager.stopMonitoring(for: circularRegion)
}
}
override func viewDidLoad() {
super.viewDidLoad()
mapView.delegate = self
mapView.userTrackingMode = .follow
mapView.showsUserLocation = true
// Region of coordinate
mapView.region = MKCoordinateRegion(center: coordinate, latitudinalMeters: 800, longitudinalMeters: 800)
mapView.region = MKCoordinateRegion(center: coordinate, latitudinalMeters: 1000, longitudinalMeters: 1000)
let title = "Marina Bar Hop"
let restaurantAnnotation = MKPointAnnotation()
restaurantAnnotation.coordinate = coordinate
restaurantAnnotation.title = title
mapView.addAnnotation(restaurantAnnotation)
let regionRadius = 300.0
let circle = MKCircle(center: coordinate, radius: regionRadius)
mapView.addOverlay(circle)
self.locationManager.requestAlwaysAuthorization()
self.locationManager.delegate = self as? CLLocationManagerDelegate
//Zoom to user location
if let userLocation = locationManager.location?.coordinate {
let viewRegion = MKCoordinateRegion(center: userLocation, latitudinalMeters: 200, longitudinalMeters: 200)
mapView.setRegion(viewRegion, animated: false)
}
}
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
let circleRenderer = MKCircleRenderer(overlay: overlay)
circleRenderer.strokeColor = UIColor.red
circleRenderer.lineWidth = 1.0
return circleRenderer
}
}
I have a few additional features on here if you need them. And it sounds like maybe you want to add a pin on the user's current location? It's included in this code too. I hope this helps! :)

How to make the annotation appear on the Apple map via Swift?

So basically, I'm calling a Rest API to get all Bus Stops location, then put annotation of all bus stops within 5km from my current location on the map when a button is called. However, it is just not displaying, I can't seem to figure out the problem.
import UIKit
import MapKit
class MapKitViewController: UIViewController, CLLocationManagerDelegate {
#IBOutlet weak var GPSButton: UIButton!
var stopSearchResults: [Value] = []
var Annotations: [BusStopAnnotation] = []
let queryServices = QueryService()
let locationManager:CLLocationManager = CLLocationManager()
#IBOutlet weak var mapView: MKMapView!
var currentLocation: CLLocationCoordinate2D?
var counter: Int = 0
override func viewDidLoad() {
super.viewDidLoad()
UIApplication.shared.isNetworkActivityIndicatorVisible = true
queryServices.GetAllBusStops(){
result in
UIApplication.shared.isNetworkActivityIndicatorVisible = false
if let result = result {
self.stopSearchResults = result.value
}
}
configureLocationService()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
private func configureLocationService() {
locationManager.delegate = self
let status = CLLocationManager.authorizationStatus()
if status == .notDetermined {
locationManager.requestAlwaysAuthorization()
} else if status == .authorizedAlways || status == .authorizedWhenInUse {
beginLocationUpdate(locationManager: locationManager)
}
}
private func beginLocationUpdate(locationManager: CLLocationManager) {
mapView.showsUserLocation = true
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.startUpdatingLocation()
}
private func zoomToLatestLocation(with coordinate: CLLocationCoordinate2D) {
let zoomRegion = MKCoordinateRegion(center: coordinate, latitudinalMeters: 1000, longitudinalMeters: 1000)
mapView.setRegion(zoomRegion, animated: true)
}
#IBAction func GPSTrack(_ sender: Any) {
InputAllAnnotation(busStops: stopSearchResults)
print("Searching for nearby bus stops")
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
print("Did get latest location")
guard let latestLocation = locations.first else { return }
if currentLocation == nil {
zoomToLatestLocation(with: latestLocation.coordinate)
}
currentLocation = latestLocation.coordinate
}
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
print("The status changed")
if status == .authorizedAlways || status == .authorizedWhenInUse {
beginLocationUpdate(locationManager: manager)
}
}
func InputAllAnnotation(busStops: [Value]) {
for busStop in busStops{
let busStopObj = BusStopAnnotation(value: busStop)
Annotations.append(busStopObj)
let distance = busStop.GetDistance(latitude: Double(currentLocation?.latitude ?? 0), longitude: Double(currentLocation?.longitude ?? 0))
if distance < 5000 {
mapView.addAnnotation(busStopObj)
}
}
}
}
extension MapKitViewController: MKMapViewDelegate {
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if let busStopAnnotation = mapView.dequeueReusableAnnotationView(withIdentifier: MKMapViewDefaultAnnotationViewReuseIdentifier) as?
MKMarkerAnnotationView {
busStopAnnotation.animatesWhenAdded = true
busStopAnnotation.titleVisibility = .adaptive
busStopAnnotation.canShowCallout = true
return busStopAnnotation
}
return nil
}
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
print("The annotation was selected: \(String(describing: view.annotation?.title))")
}
}
final class BusStopAnnotation: NSObject, MKAnnotation {
var coordinate: CLLocationCoordinate2D
var title: String?
var subtitle: String?
var busStopCode: String?
init(value : Value) {
self.coordinate = value.GetLocationCoordinate2D()
self.title = value.roadName
self.subtitle = value.description
self.busStopCode = value.busStopCode
}
init(coordinate: CLLocationCoordinate2D, roadName: String?, description: String?, busStopCode: String?) {
self.coordinate = coordinate
self.title = roadName
self.subtitle = description
self.busStopCode = busStopCode
}
var region: MKCoordinateRegion {
let span = MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05)
return MKCoordinateRegion(center: coordinate, span: span)
}
}
You may need
self.mapView.delegate = self
import:
import UIKit
import MapKit
set class
class MapViewController: UIViewController, CLLocationManagerDelegate, MKMapViewDelegate {
outlet your map
#IBOutlet weak var map: MKMapView!
Code:
let customPin : CLLocationCoordinate2D = CLLocationCoordinate2DMake(Latitude, Longitude)
let objectAnnotation = MKPointAnnotation()
objectAnnotation.coordinate = customPin
objectAnnotation.title = "Here's your custom PIN"
self.map.addAnnotation(objectAnnotation)
extra:
to set the camera near the PIN
let theSpan:MKCoordinateSpan = MKCoordinateSpan(latitudeDelta: 0.009, longitudeDelta: 0.009)
let pointLocation:CLLocationCoordinate2D = CLLocationCoordinate2DMake(Latitude, Longitude)
let region:MKCoordinateRegion = MKCoordinateRegion(center: pointLocation, span: theSpan)
self.map.setRegion(region, animated: true)
move values depending how close/far you want the camera
let theSpan:MKCoordinateSpan = MKCoordinateSpan(latitudeDelta: HERE, longitudeDelta: HERE)

Get user location when app runs and re-center again after moving around using a button

I'm working on a project about MapKit using Swift 3. What the code below does is once I load the app the map will load in default. Then when the user presses the button it takes you to the user's location.
The way I want to fix this is I want it to load the user's location as soon as the app runs, and then when the user decides to move around the screen, she/he could hit the button and then recenter the user location again. Like how it works on Maps.
import UIKit
import MapKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate {
// connecting the map from the mainBoard and refering to it as "myMap".....
#IBOutlet weak var myMap: MKMapView!
#IBAction func refLocation(_ sender: Any) {
manager.startUpdatingLocation()
}
let manager = CLLocationManager()
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let location = locations.last {
let span: MKCoordinateSpan = MKCoordinateSpanMake(0.0075,0.0075)
let myLocation :CLLocationCoordinate2D = CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longitude)
let region: MKCoordinateRegion = MKCoordinateRegionMake(myLocation, span)
myMap.setRegion(region, animated: true)
}
self.myMap.showsUserLocation = true
manager.stopUpdatingLocation()
}
override func viewDidLoad() {
super.viewDidLoad()
manager.delegate = self
manager.desiredAccuracy = kCLLocationAccuracyBest
manager.requestWhenInUseAuthorization()
}
}
It isn't clear what you're asking.
If you want to get a single location update you can use the function func requestLocation().
You could create a location manager (and set yourself as its delegate) in your view controller's viewDidLoad and call requestLocation() once.
Then call requestLocation() again in your button action.
Make your didUpdateLocations method always recenter the map. That way you'll receive one and only one update from clicking your button, and the map will recenter as soon as the update is received.
Try this code for Swift 3
import UIKit
import MapKit
import CoreLocation
class ViewController2: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
var locationManager = CLLocationManager()
var currentLocation = CLLocation()
var currentLat: Double!
var currentLon: Double!
#IBOutlet weak var mapView: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
myLocation()
}
func myLocation()
{
if currentLocation.coordinate.latitude == 0.00 || currentLocation.coordinate.longitude == 0.0
{
print("no location")
}
else
{
self.locationManager.requestWhenInUseAuthorization()
if CLLocationManager.locationServicesEnabled()
{
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
}
let locManager = CLLocationManager()
locManager.requestWhenInUseAuthorization()
if(CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedWhenInUse ||
CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedAlways)
{
currentLocation = locManager.location!
}
print("currentLongitude: \(currentLocation.coordinate.longitude)")
print("currentLatitude: \(currentLocation.coordinate.latitude)")
currentLon = currentLocation.coordinate.longitude
currentLat = currentLocation.coordinate.latitude
let span = MKCoordinateSpanMake(0.2, 0.2)
let region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: currentLat, longitude: currentLon), span: span)
mapView.setRegion(region, animated: true)
}
}
#IBAction func MyLocationBtnPressed(_ sender: Any)
{
let span = MKCoordinateSpanMake(0.1, 0.1)
let region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: currentLat, longitude: currentLon), span: span)
mapView.setRegion(region, animated: true)
}
}
You don't have to call startUpdatingLocation() again because MapView always knows userLocation.
Replace
#IBAction func refLocation(_ sender: Any) {
manager.startUpdatingLocation()
}
with
#IBAction func refLocation(_ sender: Any) {
let region: MKCoordinateRegion = MKCoordinateRegionMake(myMap.userLocation.coordinate, myMap.region.span)
mapView.setRegion(region, animated: true)
}

make pin draggable and long click

I've been trying for hours to make the pin draggable in MapKit, but it seems that the pin is so stubborn it didn't want to move.
this is my code:
import UIKit
import MapKit
protocol AddCoffeeDelegate {
func viewController(vc: AddCoffeeViewController, didAddCoffee coffee : Coffee! )
}
class AddCoffeeViewController: UIViewController, CLLocationManagerDelegate, MKMapViewDelegate {
#IBOutlet var mapView: MKMapView!
#IBOutlet weak var coffeeName: UITextField!
#IBOutlet weak var coffeeRating: UITextField!
var coffee: Coffee?
var delegate: AddCoffeeDelegate?
////////////////////////////////////////////////////
var coreLocationManager = CLLocationManager()
var locationManager : LocationManager!
var savedLocation : CLLocation?
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKPointAnnotation {
let pinAnnotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "myPin")
pinAnnotationView.pinTintColor = UIColor.redColor()
pinAnnotationView.draggable = true
pinAnnotationView.canShowCallout = false
pinAnnotationView.animatesDrop = true
return pinAnnotationView
}
return nil
}
func getLocation(){
locationManager.startUpdatingLocationWithCompletionHandler { (latitude, longitude, status, verboseMessage, error) -> () in
self.displayLocation(CLLocation(latitude: latitude, longitude: longitude))
}
}
func displayLocation(location: CLLocation){
mapView.setRegion(MKCoordinateRegion(center: CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longitude), span: MKCoordinateSpanMake(0.05, 0.05)), animated: true)
let locationPinCoord = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)
let annotation = MKPointAnnotation()
annotation.title = "My Title"
annotation.subtitle = "My Subtitle"
annotation.coordinate = locationPinCoord
mapView.addAnnotation(annotation)
savedLocation = location
}
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
if status != CLAuthorizationStatus.NotDetermined || status != CLAuthorizationStatus.Denied || status != CLAuthorizationStatus.Restricted {
getLocation()
}
}
////////////////////////////////////////////////////
override func viewDidLoad() {
super.viewDidLoad()
coreLocationManager.delegate = self
locationManager = LocationManager.sharedInstance
let authorizationCode = CLLocationManager.authorizationStatus()
if authorizationCode == CLAuthorizationStatus.NotDetermined && coreLocationManager.respondsToSelector("requestAlwaysAuthorization") || coreLocationManager.respondsToSelector("requestWhenInUseAuthorization"){
if NSBundle.mainBundle().objectForInfoDictionaryKey("NSLocationAlwaysUsageDescription") != nil {
coreLocationManager.requestAlwaysAuthorization()
}else{
print("no desscription provided ")
}
}else{
getLocation()
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBAction func cancel(sender: AnyObject) {
self.dismissViewControllerAnimated(true, completion: nil)
}
#IBAction func save(sender: AnyObject) {
var createdCoffee = Coffee()
createdCoffee.name = self.coffeeName.text!
createdCoffee.rating = Double(self.coffeeRating.text!)!
createdCoffee.place = savedLocation
self.coffee = createdCoffee
self.delegate?.viewController(self, didAddCoffee: self.coffee)
}
}
I have tried every related issue with mapkit in swift, but it seems that the pin won't drag itself.Where could the problem be? I have already set the title and implement the MKMapViewDelegate protocol, but still it wont drag.
Did you set the delegate of the mapview to the view controller either in code, or via the Storyboard?
override func viewDidLoad() {
super.viewDidLoad()
mapView.delegate = self
...
}

Getting exact location in swift iOS

I have written Swift code for current location but the code isn't giving me the exact location as Android use to locate.
For me it just give me the Country location pointing but I need the exact location for my application.
Here is my code for location
import UIKit
import MapKit
import CoreLocation
class location: UIViewController , CLLocationManagerDelegate {
#IBOutlet weak var map: MKMapView!
var locationManager: CLLocationManager!
var address : String = ""
override func viewDidLoad() {
super.viewDidLoad()
//let dataProvider = GoogleDataProvider(
if (CLLocationManager.locationServicesEnabled())
{
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
var start : CLLocation!
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
start = locations.last
let center = CLLocationCoordinate2D(latitude: start!.coordinate.latitude, longitude: start!.coordinate.longitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))
self.map.setRegion(region, animated: true)
print("function called")
let annotation = MKPointAnnotation()
annotation.coordinate = center
annotation.title = "You are Here :)"
map.addAnnotation(annotation)
let geocoder = CLGeocoder()
geocoder.reverseGeocodeLocation(manager.location!, completionHandler: {
placemarks, error in
if (error != nil)
{
print("Reverse geocoder failed with error" + error!.localizedDescription)
return
}
if let pm = placemarks?.first {
self.displayLocationInfo(pm)
}
else
{
print("Problem with the data received from geocoder")
}
})
}
}

Resources