ios - 获取用户位置

标签 ios iphone swift xcode mapkit

所以我一直在致力于一项获取用户位置的任务。
我编写了这段代码,它可以在模拟器上很好地构建和运行。
但它无法获取我当前的位置。
我是不是漏掉了什么?如果是这样,请帮忙!
这是我的代码:

Capture from Xcode

最佳答案

您可以尝试将 didUpdateLocation 更改为此。

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

        let userLocation:CLLocation = locations[0] as CLLocation

        locationManager.stopUpdatingLocation()


        let location = CLLocationCoordinate2D(latitude: userLocation.coordinate.latitude, longitude: userLocation.coordinate.longitude)

        let span = MKCoordinateSpanMake(0.05, 0.05)

        let region = MKCoordinateRegion(center: location, span: span)

        myMap.setRegion(region, animated: true)


    }

希望对您有帮助。

关于ios - 获取用户位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39707949/

相关文章:

iphone - 寻找一种优雅的方法来检查字典中是否存在键

swift - 返回错误数据的 Realm

iphone - touchesBegan 没有响应

iphone - UIView 转换期间的枚举突变WithView

iphone - 停止位置 :fixed from zooming with user in iOS?

swift - 如何在不重新加载 Controller 的情况下更新用户在线状态?

swift - 将 Firebase 与 tvOS 结合使用

javascript - 为什么 hammer.js 滑动不适用于 iPhone

ios - 连接到 Apple Music

iOS 7.1 更新打破了 External Accessory inputStream UART 读取能力