作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试使用 MapBox 响应用户在 iOS 应用程序中的位置变化,但未调用 didUpdateUserLocation
。为什么不调用 didUpdateUserLocation
?
ViewController.swift
import UIKit
import Mapbox
class ViewController: UIViewController, MGLMapViewDelegate {
@IBOutlet weak var upButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
let styleURL = NSURL(string: "mapbox://styles/jmeyers919/cj8w00yxvfrqr2rpehxd47up1") // MGLStyle.darkStyleURL()
let mapView = MGLMapView(frame: view.bounds, styleURL: styleURL as URL?)
mapView.delegate = self
mapView.logoView.isHidden = true
mapView.attributionButton.isHidden = true
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
// Note that we have changed the center coordinate to New York City for this guide
// mapView.setCenter(CLLocationCoordinate2D(latitude: 44.0475276, longitude: -123.08927319), zoomLevel: 16, animated: false)
mapView.userTrackingMode = .follow
mapView.showsUserLocation = true
view.addSubview(mapView)
self.view.bringSubview(toFront: self.upButton)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func mapView(mapView: AnyObject!, didUpdateUserLocation userLocation: AnyObject!) {
print("didUpdateUserLocation")
}
}
最佳答案
当 showsUserLocation
属性设置为 YES
时,调用此方法 每本地图 View 收到新的位置更新时。这个方法也是 如果 map View 的用户跟踪模式设置为 MGLUserTrackingModeFollowWithHeading
和航向改变,或者如果它被设置 到 MGLUserTrackingModeFollowWithCourse
并且类(class)更改。
如果应用程序当前在后台运行,则不会调用此方法。如果您想在运行时接收位置更新 后台,必须使用Core Location框架。
关于swift - MapBox didUpdateUserLocation 从未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46800207/
背景 我最近在 merge 期间遇到了一个意外未 merge 的文档文件的问题。 无论出于何种原因,我搞砸了 merge 并有效地删除了文件(和其他几个文件),因为我忘记了它们的存在。 现在我想查看我
我在我的网站上使用旧的 mysql 版本和 php 版本 4。 我的表结构: | orders_status_history_id | orders_id | orders_status_id |
我是一名优秀的程序员,十分优秀!