我大概花了6个小时对这个问题进行了研究和尝试,并陷入了困境--帮助!
我在世界各地创建了一组简单的纵向多线线,当日期线(反子午线)在180度E/W可见时,我会发现奇怪的行为。如果完全放大,所有的复线正确显示,但一旦我开始放大,反子午线以东的线开始消失。如果我放大,线会重新出现。或者,如果我平移到地图上,所以蚂蚁线/日期线就在视图的左边边缘,那么所有的线也会重新出现(不管缩放级别如何)!我在下面展示4张截图:




我的密码在下面。对每个区域更新都调用绞车网格()函数。这在iOS 8+ iPhone 6模拟器和实际设备(运行iOS 7.1的iPhone 4)中都是相同的。
func drawgrid() {
var b: [CLLocationCoordinate2D] = []
for var x = -179.99; x <= 179.99; x = x + 1.0 { // I tried -180.0 to 180.0 as well -> no effect
let c1 = CLLocationCoordinate2D(latitude: 90.0, longitude: x) // Tried 80.0 as well
let c2 = CLLocationCoordinate2D(latitude: -90.0, longitude: x) // Tried -80.0 as well
b = [c1, c2]
var polyline = MKPolyline(coordinates: &b, count: b.count)
mapView.addOverlay(polyline)
}
}
func mapView(mapView: MKMapView!,regionDidChangeAnimated animated: Bool) {
mapView.removeOverlays(mapView.overlays) // Already tried commenting this out (it's for a different purpose elsewhere in the app)
drawgrid()
MyLabel.text = "Span = \(mapView.region.span.longitudeDelta) deg"
MyLabel2.text = "Center = \(mapView.region.center.longitude) \(mapView.region.center.latitude)"
}
func mapView(mapView: MKMapView!, rendererForOverlay overlay: MKOverlay!) -> MKOverlayRenderer! {
if overlay is MKPolyline{
var polylineRenderer = MKPolylineRenderer(overlay: overlay)
polylineRenderer.strokeColor = UIColor.redColor()
polylineRenderer.lineWidth = 0.1 // tried thicker value of 1.0 too
return polylineRenderer
}
return nil
}任何和所有的帮助都非常感谢!我是个新手(几周前刚开始编码),所以如果你能用Swift而不是Objective提供指导的话,我就不会把头撞到桌子上了。谢谢!
编辑11/22/2014:仍然存在这个问题,它似乎不仅影响覆盖,而且影响注释。只要国际日期行在视图中,我所有的注释都会消失,不管它们在地图上的位置。仍然找不到办法绕过这件事,它闻起来真像一只虫子.
发布于 2014-10-14 01:33:14
添加以下println()。
func mapView(mapView: MKMapView!,regionDidChangeAnimated animated: Bool) {
println("region did change*****************************") // Added
mapView.removeOverlays(mapView.overlays) // Already tried commenting this out (it's for a different purpose elsewhere in the app)
drawgrid()
MyLabel.text = "Span = \(mapView.region.span.longitudeDelta) deg"
MyLabel2.text = "Center = \(mapView.region.center.longitude) \(mapView.region.center.latitude)"
}和
func mapView(mapView: MKMapView!, rendererForOverlay overlay: MKOverlay!) -> MKOverlayRenderer! {
if overlay is MKPolyline{
var polylineRenderer = MKPolylineRenderer(overlay: overlay)
polylineRenderer.strokeColor = UIColor.redColor()
polylineRenderer.lineWidth = 1 // tried thicker value of 1.0 too
println("Lonitude " + "\(overlay.coordinate.longitude)") //Added
return polylineRenderer
}
return nil
}然后运行您的应用程序并查看控制台框,您将看到您的值显示为正常,直到您到达问题区域,然后负经度在某个点被切断。
查找renderForOverlay函数的引用。ref/occ/instm/MKMapView/addOverlays:它说,正在包围的多边形与地图的视图部分相交,它将被呈现(我认为是那些不会被渲染的)。我相信这可能是你的问题。
https://stackoverflow.com/questions/26344094
复制相似问题