iT邦幫忙

2024 iThome 鐵人賽

DAY 5
0
Mobile Development

手機Swift性能專家系列 第 5

手機地圖使用基本介紹

  • 分享至 

  • xImage
  •  

今天我們要介紹 MapKit 手機地圖我們需要先在Info 裡面加入確認請求位子的請求
加入完後

import CoreLocation

class ViewController: UIViewController, CLLocationManagerDelegate {
    let locationManager = CLLocationManager()

    override func viewDidLoad() {
        super.viewDidLoad()

        locationManager.delegate = self
        locationManager.requestWhenInUseAuthorization()
        locationManager.startUpdatingLocation()
    }

    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        if let location = locations.first {
            centerMapOnLocation(location: location)
        }
    }

    func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
        print("Error while updating location: \(error.localizedDescription)")
    }
}

透過上面程式就可以獲取用戶的地理位子


上一篇
開啟iOS相簿的方法
下一篇
swift 地圖擴充功能介紹
系列文
手機Swift性能專家20
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言