2012-02-03 28 views

回答

-1

這個答案告訴你如何比較兩個地圖點。你可以在地圖區域的中心使用它:link

+0

感謝您重新申請。 – Nit 2012-02-03 05:42:10

+0

這不是對兩個點之間的距離而不是兩個區域之間的距離進行比較的問題的答案。 – 2014-08-20 08:14:53

0

首先你需要找到初始地圖區域。說你的地圖被命名爲MapView的......你可以先通過(在viewDidLoad中)找到此:

CLLocationCoordinate2D center = mapView.centerCoordinate; 
CLLocationDegrees lat = center.latitude; 
CLLocationDegrees lon = center.longitude; 

MKCoordinateRegion region = mapView.region; 
MKCoordinateSpan span = region.span; 

//Assuming they have been declared as instance variables of type double 
current_lat_low = lat - span.latitudeDelta/2.0; 
current_lat_high = lat + span.latitudeDelta/2.0; 
current_lon_low = lon - span.longitudeDelta/2.0; 
current_lon_high = lon + span.longitudeDelta/2.0; 

這會給你顯示的地圖的初始區域。然後在

- (void)mapView:(MKMapView*)mapView regionDidChangeAnimated:(BOOL)animated 
{ 

    CLLocationCoordinate2D center = mapView.centerCoordinate; 
    CLLocationDegrees lat = center.latitude; 
    CLLocationDegrees lon = center.longitude; 

    MKCoordinateRegion region = mapView.region; 
    MKCoordinateSpan span = region.span; 

    double lat_low = lat - span.latitudeDelta/2.0; 
    double lat_high = lat + span.latitudeDelta/2.0; 
    double lon_low = lon - span.longitudeDelta/2.0; 
    double lon_high = lon + span.longitudeDelta/2.0; 

    //do any work comparing the initial lat/lons with the new values 
    ..... 

    //set current lat/lon to be the new lat/lon after work is complete 
    current_lat_low = lat_low; 
    current_lat_high = lat_high; 
    current_lon_low = lon_low; 
    current_lon_high = lon_high; 
} 
相關問題