2011-09-11 362 views

回答

88

另一種方法是使用MapKit的MKCoordinateRegionMakeWithDistance函數:

MKCoordinateRegion rgn = MKCoordinateRegionMakeWithDistance(
    CLLocationCoordinate2DMake(someLatitude, someLongitude), 500, 500); 

MKCoordinateSpan將在rgn.span

+5

+1,這是簡單的方法 - 我不知道那個! –

+2

這真的很不錯 – Eugene

39

除非您需要很高的準確性,否則您可以使用近似值更容易。第一個問題是找到代表500米緯度的部分。因爲緯度在任何地點都是常數,大約111公里。所以500米緯度爲0.0045度。

然後它會變得更難,因爲經度的長度取決於你的位置。它可以與

enter image description here

其中alpha是地球赤道半徑,6378137公里,B/A爲0.99664719(在使用中用於在使用中的WGC84球體模型由所有GPS設備提供恆定的)和enter image description here其中phi來近似是緯度。

想象一下,你很幸運能夠在墨爾本以37.783度的經度在墨爾本。北方或南方在這裏並不重要。測試的結果是37.6899,其餘部分解決了縱向度爲88公里的問題。所以500米是一度的.0057。

結果墨爾本 - MKCoordinateSpan melbourne500MeterSpan = MKCoordinateSpanMake(.0045, .0057);

你可以檢查你的答案和你的代碼with this online calculator

經度的wiki article對這個有很多更詳細的(而且這裏的圖片的來源)

代碼:

#define EARTH_EQUATORIAL_RADIUS (6378137.0) 
#define WGS84_CONSTANT (0.99664719) 

#define degreesToRadians(x) (M_PI * (x)/180.0) 

// accepts decimal degrees. Convert from HMS first if that's what you have 
double spanOfMetersAtDegreeLongitude(double degrees, double meters) { 

    double tanDegrees = tanf(degreesToRadians(degrees)); 
    double beta = tanDegrees * WGS84_CONSTANT; 
    double lengthOfDegree = cos(atan(beta)) * EARTH_EQUATORIAL_RADIUS * M_PI/180.0; 
    double measuresInDegreeLength = lengthOfDegree/meters; 
    return 1.0/measuresInDegreeLength; 
} 
+3

哇。現在這是一個答案。太糟糕了,我只能給你一個大拇指... –

+1

請不要使用此答案。儘可能滿足要求,MKCoordinateRegionMakeWithDistance是正確的方法。 –

-2

在MonoTouch中,然後使用該解決方案您可以使用此helper方法:

public static void ZoomToCoordinateAndCenter (MKMapView mapView, CLLocationCoordinate2D coordinate, double meters, bool showUserLocationToo, bool animate) 
    { 
     if (!coordinate.IsValid()) 
      return; 

     mapView.SetCenterCoordinate (coordinate, animate); 
     mapView.SetRegion (MKCoordinateRegion.FromDistance (coordinate, meters, meters), animate);  
    } 
+9

-1強迫我谷歌MonoTouch。 – sean

+0

單點觸控解決方案沒有問題! –

相關問題