2010-09-30 108 views
0

我試圖把一個註解當前可見的地圖區域的左下角一個MapView關閉的左下角,雖然下面的代碼座標幾個像素

CLLocationCoordinate2D origin = getOriginOfRegion(mapView.region); 
[[[SimpleAnnotation alloc] initWithCoords:origin] autorelease]; 
... 
extern CLLocationCoordinate2D getOriginOfRegion(MKCoordinateRegion region){ 
    return CLLocationCoordinate2DMake(region.center.latitude-region.span.latitudeDelta/2, 
            region.center.longitude-region.span.longitudeDelta/2); 
} 

其中SimpleAnnotation是它很簡單,把針點幾度離實際的彎道:

在右側縮放級別更高,因爲你可以看到的錯誤是顯著更小。

我試着做一些數學來對付它,考慮到這個錯誤可能與橢圓座標投影到飛機上有關,但沒有提出任何有用的東西。

有沒有人解決過這個問題?我注意到mapView上的緯度值不是'線性的',我需要一些提示來理解如何轉換它們。

回答

2

我不知道這是否可行,但我建議你試着讓地圖視圖轉換視圖座標到地圖座標convertPoint:toCoordinateFromView:

例如:

CGPoint bottomLeftPoint = CGPointMake(CGRectGetMinX(map.bounds), CGRectGetMaxY(map.bounds)); 
CLLocationCoordinate2D bottomLeftCoord = [map convertPoint:bottomLeftPoint toCoordinateFromView:map]; 
+0

我相信這會工作,但我試圖瞭解它背後的數學。 – Pyetras 2010-09-30 20:15:46

+0

我無法解釋它。根據維基百科,緯度和緯度之間的一度緯度的長度只有很小的變化(約1%)。 – 2010-09-30 20:47:03