我正在尝试在我的苹果应用程序中显示楼层水平。我知道在苹果地图上有一些选定的地方,比如机场或购物中心,在那里可以看到楼层的高度。我需要做到这一点。只需要显示这是可用的地板水平。正如你在图片中看到的,在图片的右边有5F,4F,3F,2F等。我已经在网上搜索过了,但离开时还没有任何线索。

发布于 2019-02-12 21:54:11
您需要使用MKOverlay。您可以将每个楼层作为覆盖添加到您的MKMapView,并显示用户选择的任何楼层,隐藏其他楼层。
下面是一个生成覆盖图的示例:
import MapKit
class MapOverlay: NSObject, MKOverlay {
var coordinate: CLLocationCoordinate2D
var boundingMapRect: MKMapRect
override init() {
let location = CLLocationCoordinate2D(latitude: 75.3307, longitude: -152.1929) // change these for the position of your overlay
let mapSize = MKMapSize(width: 240000000, height: 200000000) // change these numbers for the width and height of your image
boundingMapRect = MKMapRect(origin: MKMapPoint(location), size: mapSize)
coordinate = location
super.init()
}
}
class MapOverlayRenderer: MKOverlayRenderer {
let overlayImage: UIImage
init(overlay: MKOverlay, image: UIImage) {
self.overlayImage = image
super.init(overlay: overlay)
}
override func draw(_ mapRect: MKMapRect, zoomScale: MKZoomScale, in context: CGContext) {
guard let imageReference = overlayImage.cgImage else { return }
let rect = self.rect(for: overlay.boundingMapRect)
context.scaleBy(x: 1.0, y: -1.0)
context.translateBy(x: 0.0, y: -rect.size.height)
context.draw(imageReference, in: rect)
}
}然后将其添加到您的地图:
let mapOverlay = MapOverlay()
mapView.addOverlay(mapOverlay)别忘了委派:
mapView.delegate = self
extension ViewController: MKMapViewDelegate {
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
return MapOverlayRenderer(overlay: overlay, image: UIImage(named: "overlayImage")!)
}
}https://stackoverflow.com/questions/54648577
复制相似问题