- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在 MKMapView 中显示某个 map 区域,但是当我在 map 上放置一个具有相同参数的矩形叠加层时,它会垂直显示不对齐。在赤道附近看起来足够好,但偏差随着纬度和跨度的增加而增加。
这是针对 Mac 应用程序的,但对于 iOS 来说应该是相同的。
这是我的相关代码:
MKCoordinateRegion mapRegion = MKCoordinateRegionMake(CLLocationCoordinate2DMake(latCenter, lonCenter), MKCoordinateSpanMake(mapWidthY, mapWidthX));
self.radarMap.region = mapRegion;
CLLocationCoordinate2D coordinates[4];
coordinates[0] = CLLocationCoordinate2DMake(latCenter+mapWidthY/2, lonCenter+mapWidthX/2);
coordinates[1] = CLLocationCoordinate2DMake(latCenter+mapWidthY/2, lonCenter-mapWidthX/2);
coordinates[2] = CLLocationCoordinate2DMake(latCenter-mapWidthY/2, lonCenter-mapWidthX/2);
coordinates[3] = CLLocationCoordinate2DMake(latCenter-mapWidthY/2, lonCenter+mapWidthX/2);
self.boundaryOverlay = [MKPolygon polygonWithCoordinates:coordinates count:4];
[self.radarMap addOverlay:self.boundaryOverlay];
它显示了这一点:(请注意,蓝色矩形覆盖层向上移动,因此上部区域不会显示):
而不是这样的:(我知道它以宽高比填充显示):
最佳答案
当您设置 MKMapView 对象的区域属性时,MapKit 会调整区域属性的值,使其与实际可见区域相匹配。这意味着区域的实际值并不完全是您分配给它的值。因此,您应该从 MKMapView 对象获取区域的更新值并使用它来创建多边形,而不是使用分配给 map 的区域来创建多边形。
MKCoordinateRegion mapRegion = MKCoordinateRegionMake(CLLocationCoordinate2DMake(latCenter, lonCenter), MKCoordinateSpanMake(mapWidthY, mapWidthX));
self.radarMap.region = mapRegion;
CLLocationCoordinate2D coordinates[4];
// Get the actual region that MapKit is using
MKCoordinateRegion actualMapRegion = self.radarMap.region;
CLLocationDegrees actualLatCenter = actualMapRegion.center.latitude;
CLLocationDegrees actualLonCenter = actualMapRegion.center.longitude;
CLLocationDegrees actualLatSpan = actualMapRegion.span.latitudeDelta;
CLLocationDegrees actualLonSpan = actualMapRegion.span.longitudeDelta;
// And use that to create the polygon
coordinates[0] = CLLocationCoordinate2DMake(actualLatCenter+ actualLatSpan/2, actualLonCenter+ actualLonSpan/2);
coordinates[1] = CLLocationCoordinate2DMake(actualLatCenter+ actualLatSpan/2, actualLonCenter-actualLonSpan/2);
coordinates[2] = CLLocationCoordinate2DMake(actualLatCenter-actualLatSpan/2, actualLonCenter-actualLonSpan/2);
coordinates[3] = CLLocationCoordinate2DMake(actualLatCenter-actualLatSpan/2, actualLonCenter+ actualLonSpan/2);
self.boundaryOverlay = [MKPolygon polygonWithCoordinates:coordinates count:4];
[self.radarMap addOverlay:self.boundaryOverlay];
当你向北移动时,我对你所看到的日益增加的错位感到好奇。我想到您可能对mapWidthX 和mapWidthY 使用固定比率。 MapKit 使用非等角投影。这样做的结果之一是 map 在南北方向上拉伸(stretch),距离赤道越远拉伸(stretch)得越多。
如果您使用适合赤道的比例创建区域,则当您向两极移动时,该比例将会不正确。 MKMapView 将获取您提供的区域并显示靠近它的内容。但距离赤道越远,需要进行的调整就越多。而且你给它的区域和它实际使用的区域之间的差异就越大。
关于cocoa - MKMapView 与其区域属性未对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27031786/
在我当前设计的应用程序中,我有一个带有覆盖层的 MKMapView (顺便说一句,自定义的 MKPolylines),我希望能够检测到触摸事件这些覆盖层并为每个覆盖层分配特定的操作。有人可以帮我解决这
我在我的 .xib 上放置了一个 MKMapView。 它工作正常,但我需要 map 根据罗盘方向旋转? 我读过有关“指南针模式”的内容。 也许我需要将 compassMode 的 MKMapView
我有一个带有注册委托(delegate)的 MKMapView,因此我可以监听区域更改事件(具体来说,regionDidChangeAnimated)。我正在寻找一种可靠的方法来判断区域更改事件是用户
我正在尝试将 MKAnnotationView 添加到 MKMapView 但我做不到……有人能帮我吗? 这是我的代码: override func viewDidLoad() { super
我想像照片应用程序中那样隐藏和显示导航栏但不会丢失 MKMapView 的功能。用户仍然应该能够双击进行缩放、捏合和缩放,并能够选择注释。 我试过: UITapGestureRecognizer*
我在 MKMapView 上有一个 MKCircle。它是用户可拖动的,但如果用户拖动圆圈外的区域, map 应该会移动。 - (IBAction)createPanGestureRecognizer
我正在开发一款与 map 配合使用的 iPhone 应用程序。在此应用程序中,我需要根据纬度和经度显示一些 parking 位(地址)。至此,我成功完成了,但我想显示相对于用户方向(SE、SW、NE、
如何比较 MKMapView 的当前跨度?我正在使用以下代码: - (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)a
我们在我们的一个应用程序中看到了意外行为 - 我们在一个屏幕上显示 map View 上的注释,用户可以通过单击按钮更改显示的注释。 当我们用 iOS7 重建应用程序时,屏幕会定期卡住,即一旦下面的代
我正在尝试创建一个带有 MKMapView 和一个导航到用户位置的按钮的 SwiftUI View 。以下是我的全部代码。我创建了一个名为 MapView 的 View ,它符合 UIViewRepr
我的代码在iOS 7到8上运行良好。昨天进行了更新,我的图钉上的自定义图像已替换为标准的图钉图像。 有什么建议? 我的代码: extension ViewController: MKMapViewDe
我可以使用 MKMApView 组件创建一个 iOS 商业应用程序(在应用程序商店中花费几美元下载)吗? 我知道它是基于 Google 图片,所以...我不知道。 最佳答案 当然,MapKit 已用于
我有用户位置和边界。边界有8个坐标。我需要检查用户是否在边界内。我正在 iPhone 中使用 MapView。 提前致谢。 最佳答案 使用 Map Kit 中的一些内置函数来执行此操作的一种方法是将边
我有一个 MkMapView,并希望将 map 保持在用户位置的中心,就像按下范围按钮时 iPhone map 应用程序所做的那样。 我使用 setCenterCoordinate 方法,因为我不需要
浏览了这里的一些问题后,我对缩放级别和 MKMapView 有了一个大概的了解。然后我发现了这个很棒的博客: http://troybrant.net/blog/2010/01/set-the-zoo
我有一个使用以下代码删除 pin 的功能: ParkPlaceMark *placemark=[[ParkPlaceMark alloc] initWithCoordinate:location];
双击 MKMapView 时:放大。 但是如何缩小呢? 最佳答案 总是使用两根手指来放大和缩小。在模拟器上,您需要按住选项键才能在模拟屏幕上显示“两根手指”(我认为这是 Alt 键,但我在 Mac 上
释放 MKMapView 后,我遇到了奇怪的(?)崩溃。 MKMapView 是我的 View Controller 中的 subview ,在我从导航堆栈中删除该 View 并释放它后,应用程序崩溃
我通过单击按钮缩小 map 。 因此,本地图完全缩小时,如果我尝试再次缩小它,那么它在设置区域时会崩溃。 不确定,但是,有没有办法检测 map 是否达到最大缩放限制? 这是我缩小 map 的代码 -(
我需要获得某种比例因子,它可以告诉我 map 缩放了多少(每当区域发生变化时)。 我的第一个想法是使用跨度的纬度或经度增量值。我会跟踪“旧”值,然后在 map 区域发生变化时更新该值,并将比率与旧值进
我是一名优秀的程序员,十分优秀!