【发布时间】:2018-01-16 20:49:37
【问题描述】:
我有一张上面有自定义 UIView 的地图。我正在根据缩放级别计算圆的半径。
func getCenterCoordinate() -> CLLocationCoordinate2D {
let centerPoint = self.mapView.center
let centerCoordinate = self.mapView.projection.coordinate(for: centerPoint)
return centerCoordinate
}
func getTopCenterCoordinate() -> CLLocationCoordinate2D {
// to get coordinate from CGPoint of your map
let topCenterCoor = self.mapView.convert(CGPoint(x:self.circleView.frame.size.width / 2.0, y:0), from: self.circleView)
let point = self.mapView.projection.coordinate(for: topCenterCoor)
return point
}
func getRadius() -> CLLocationDistance {
let centerCoordinate = getCenterCoordinate()
// init center location from center coordinate
let centerLocation = CLLocation(latitude: centerCoordinate.latitude, longitude: centerCoordinate.longitude)
let topCenterCoordinate = self.getTopCenterCoordinate()
let topCenterLocation = CLLocation(latitude: topCenterCoordinate.latitude, longitude: topCenterCoordinate.longitude)
let radius = CLLocationDistance(centerLocation.distance(from: topCenterLocation)) / 1000
print(radius)
return round(radius)
}
现在,我想根据给定的半径缩放地图?我怎么能这样做?
【问题讨论】:
-
您的地图是矩形的,那么您希望如何将圆形映射到矩形?一旦你决定了,你只需要打电话给
mapView.setRegion()。 -
请检查我的回答。希望对您有所帮助。
标签: ios swift google-maps