Location Services รวบรวมตำแหน่งจาก GPS, WiFi, Cell Towers ทุก iPhone มี GPS, WiFi, Bluetooth ตัวกำกับตำแหน่ง ผู้ใช้เปิด/ปิดได้ใน Settings → General → Location Services
ควรตรวจสอบ locationServicesEnabled() ก่อนเริ่ม Location Updates
โค้ดตรวจสอบ
ใน ViewController สร้างฟังก์ชัน:
func isLocationAccessEnabled() {
if CLLocationManager.locationServicesEnabled() {
switch CLLocationManager.authorizationStatus() {
case .notDetermined, .restricted, .denied:
print("No access")
case .authorizedAlways, .authorizedWhenInUse:
print("Access")
}
} else {
print("Location services not enabled")
}
}