Xcode MKMapView未被称为Swift ios 8
嗨,我只是想知道为什么我的MapView函数没有被调用。我试图在点与点之间画一条线,但所显示的只是中心位置。 提前谢谢。 导入UIKit 导入核心定位 导入地图套件 第三类视图控制器:UIViewController、CLLocationManagerDelegate{Xcode MKMapView未被称为Swift ios 8,xcode,swift,ios8,mkmapview,Xcode,Swift,Ios8,Mkmapview,嗨,我只是想知道为什么我的MapView函数没有被调用。我试图在点与点之间画一条线,但所显示的只是中心位置。 提前谢谢。 导入UIKit 导入核心定位 导入地图套件 第三类视图控制器:UIViewController、CLLocationManagerDelegate{ @IBOutlet weak var theMap: MKMapView! @IBOutlet weak var theLabel: UILabel! var manager:CLLocationManager!
@IBOutlet weak var theMap: MKMapView!
@IBOutlet weak var theLabel: UILabel!
var manager:CLLocationManager!
var myLocations: [CLLocation] = []
override func viewDidLoad() {
super.viewDidLoad()
//Setup our Location Manager
manager = CLLocationManager()
self.manager.delegate = self
manager.desiredAccuracy = kCLLocationAccuracyBest
manager.requestAlwaysAuthorization()
manager.startUpdatingLocation()
//Setup our Map View
// theMap.delegate = self
theMap.mapType = MKMapType.Standard
theMap.showsUserLocation = true
}
func locationManager(manager:CLLocationManager, didUpdateLocations locations:[AnyObject]) {
theLabel.text = "\(locations[0])"
myLocations.append(locations[0] as CLLocation)
let spanX = 0.007
let spanY = 0.007
var newRegion = MKCoordinateRegion(center: theMap.userLocation.coordinate, span: MKCoordinateSpanMake(spanX, spanY))
theMap.setRegion(newRegion, animated: true)
println("not yet ")
if (myLocations.count > 1){
println("here ")
var sourceIndex = myLocations.count - 1
var destinationIndex = myLocations.count - 2
let c1 = myLocations[sourceIndex].coordinate
let c2 = myLocations[destinationIndex].coordinate
var a = [c1, c2]
var polyline = MKPolyline(coordinates: &a, count: a.count)
theMap.addOverlay(polyline)
}
}
func mapView(mapView: MKMapView!, rendererForOverlay overlay: MKOverlay!) -> MKOverlayRenderer! {
println("sad")
if overlay is MKPolyline {
println("aadsfsad")
var polylineRenderer = MKPolylineRenderer(overlay: overlay)
polylineRenderer.strokeColor = UIColor.blueColor()
polylineRenderer.lineWidth = 4
return polylineRenderer
}
return nil
}
}ios8+MapView中的未自动加载LocationCoordinate。如果我们想使用MKMapView以“mapView:didUpdateUserLocation”加载更精确的位置: 前提:
1.设置mapView委托。
2.设置显示支持位置:是
3.mapView必须在容器中(addSubview:mapView) 例如:
self.mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
_mapView.delegate = self;
[_mapView setShowsUserLocation:YES];
[[UIApplication sharedApplication].keyWindow addSubview:_mapView];
是因为您正在检查myLocations>1。应该是myLocations>0。如果我把它改为0,那么我会从索引错误中得到一个数组,所以我算出了。我没有将映射委托给self。因此,视图中的map.delegate=self没有加载,这就是覆盖没有出现的原因。您好。此问题标记为“swift”:请提供swift中的代码。非常感谢。