2016-10-28 36 views
0

我正在處理與交付相關的應用程序。在這個應用程序中,一個視圖顯示地圖視圖。如果地圖視圖改變其區域,那麼如何從當前位置查找地圖視圖區域的方向?如何檢測在哪個方向上的地圖視圖更改區域

+0

也許你可以使用CLLocationCoordinate2D並調用didChangeRegion當檢測每次根據地圖中心的方向嗎? –

回答

0

您可以創建,存儲最後一次中心座標,然後找到新的和最後的中心座標之間的方向,使用該方法從這個答案https://stackoverflow.com/a/6140171/1757960

事情是這樣的一個屬性:

創建屬性

@property (assign, nonatomic) CLLocationCoordinate2D lastCenterCoordinate; 

實現委託

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated 
{ 
    float angle = [self angleFromCoordinate:self.lastCenterCoordinate toCoordinate:mapView.centerCoordinate]; 

    self.lastCenterCoordinate = mapView.centerCoordinate; 
} 

僅供參考,這裏的上述

+ (float)angleFromCoordinate:(CLLocationCoordinate2D)first 
       toCoordinate:(CLLocationCoordinate2D)second 
{ 

    float deltaLongitude = second.longitude - first.longitude; 
    float deltaLatitude = second.latitude - first.latitude; 
    float angle = (M_PI * .5f) - atan(deltaLatitude/deltaLongitude); 

    if (deltaLongitude > 0)  return angle; 
    else if (deltaLongitude < 0) return angle + M_PI; 
    else if (deltaLatitude < 0) return M_PI; 

    return 0.0f; 
} 

鏈接從答案的方法(請注意,這是未測試)

+0

hii jota我試過了。這給了我角度不是方向。我想顯示從ABC廣場左邊的用戶的當前位置的方向 –

相關問題