0

I like to know if it is possible to find the Latitude and the Longitude on iPhone that is not connected to WIFI and using cellular data while inside a building with Swift?

IF not what is the alternative way of determine that?

borna
  • 906
  • 3
  • 12
  • 32
  • 1
    Possible duplicate of [How to get current longitude and latitude using CLLocationManager-Swift](http://stackoverflow.com/questions/26741591/how-to-get-current-longitude-and-latitude-using-cllocationmanager-swift) – Nat Jan 30 '16 at 20:13

1 Answers1

3

For iOS 8 and swift2.3 add your project's info.plist privacy for always location use and then use this code

let locationManager = CLLocationManager()
var userLatitude:CLLocationDegrees! = 0
var userLongitude:CLLocationDegrees! = 0

use this code in viewDidLoad -

self.locationManager.requestAlwaysAuthorization()
self.locationManager.requestWhenInUseAuthorization()

if CLLocationManager.locationServicesEnabled()

{
    locationManager.delegate = self
    locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
    locationManager.startMonitoringSignificantLocationChanges()

    userLatitude  = locationManager.location?.coordinate.latitude
    userLongitude  = locationManager.location?.coordinate.longitude
}
Tunaki
  • 132,869
  • 46
  • 340
  • 423
pawan gupta
  • 251
  • 4
  • 7