2017-03-08 3 views
-1

MKMapViewに円を描きます。しかし、このサークルの半径を計算して、最初にサークルを描くために使用された半径の値と同じになるようにするにはどうすればよいですか?MKMapView - 設定と一致する半径を計算する方法

func setArea(_ center:CLLocationCoordinate2D, radius:CLLocationDistance) { 

    let area = MKCircle(center:center, radius:radius/LocationViewController.kRadiusInset) 
    mapView.setVisibleMapRect(mapView.mapRectThatFits(area.boundingMapRect), animated:false) 
} 

は、私は次のことを試してみたが、それは非常にわずかsetAreaに渡さradiusよりも大きな値を返します。マップの中心から左端までの距離を計算します。

// getRadius 
let distance = middle.distance(from: edge) 
let middle = CLLocation(latitude: mapView.region.center.latitude, longitude: mapView.region.center.longitude) 
let edge = CLLocation(latitude: mapView.region.center.latitude, longitude: mapView.centerCoordinate.longitude - (mapView.region.span.longitudeDelta * 0.5)) 

let distance = middle.distance(from: edge) 

私はsetArea()に「4000」メートルに渡し、その後、その後mapViewDidFinishRenderingMap()以内に私は4010.61219348448

なぜ食い違い?

答えて

0

を取得し、たとえば(マップの半径を計算する場合、私はAの使用を置き換えますMKCircleを次のように使用してください:

これはあまり正確ではありません。 MKMapViewのregionを設定した後、私は4000.00048143541になります。この違いは、ユーザーインターフェイスには入り込みますが、私の最初のアプローチほど速くはありません。

誰でも近づけることができますか?

関連する問題