sách gpt4 ai đã đi

swift - MKMapView 边界

In lại 作者:行者123 更新时间:2023-11-30 10:42:14 29 4
mua khóa gpt4 Nike

我将从 Google map 转到 Apple map 。 Google map 能够根据东北和西南坐标更新相机,如下所示:

let bounds = GMSCameraUpdate.fit(GMSCoordinateBounds(northEastSouthWestBounds), with: .zero)
self.mapView.moveCamera(bounds)

我知道我可以使用 setVisibleMapRect(_:animated:) 并且它接受 MKMapRect。我真正的问题是如何根据东北坐标(CLLocation)和西南坐标(CLLocation)创建MKMapRect.

1 Câu trả lời

构造一个MKMapRect从您的坐标并将其传递给 setVisibleMapRect(_:animated:)hoặcsetVisibleMapRect(_:edgePadding:animated:) .

要从不同点类型的数组创建 MKMapRect:

import MapKit

extension Array where Element == CLLocationCoordinate2D {
func mapRect() -> MKMapRect? {
return map(MKMapPoint.init).mapRect()
}
}

extension Array where Element == CLLocation {
func mapRect() -> MKMapRect? {
return map { MKMapPoint($0.coordinate) }.mapRect()
}
}

extension Array where Element == MKMapPoint {
func mapRect() -> MKMapRect? {
guard count > 0 else { return nil }

let xs = map { $0.x }
let ys = map { $0.y }

let west = xs.min()!
let east = xs.max()!
let width = east - west

let south = ys.min()!
let north = ys.max()!
let height = north - south

return MKMapRect(x: west, y: south, width: width, height: height)
}
}

关于swift - MKMapView 边界,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56549632/

29 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com