我有一個地圖上有一個自定義的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()'。 –
請檢查我的答案。希望它能幫助你。 – Rex