![](/img/trans.png)
[英]Is there a way to find the state the user is in with the iphone's MapKit?
[英]MapKit Find User Only When Map Loads
我希望有人可以指點我方便的委托方法來回答以下問題。
我的問題是:我怎么知道MapKit第一次找到了用戶?
當我的視圖出現時,我會告訴我的MKMapView找到用戶並在用戶周圍設置地圖區域。 在最初找到用戶之后,我不想繼續將地圖更新到他/她的位置。 我想讓用戶自由地在地圖上平移,而不是自動回到他們的位置。
當找到用戶時出現延遲時我遇到了麻煩(例如,用戶第一次打開應用程序時,MapKit在他/她同意共享其位置之前找不到用戶)。 結果是地圖在大西洋上空的某處打開,一旦找到用戶,它就無法自行修正。
不幸的是, - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation在確定用戶的真實位置之前被調用了幾次(測試時,在我同意共享我的位置之前,我看到了它的NSLog語句)。
- (void)viewDidLoad
{
[super viewDidLoad];
self.mapView.delegate=self;
}
-(void)viewWillAppear:(BOOL)animated{
[self.mapView setShowsUserLocation:YES];
[self.mapView setUserTrackingMode: MKUserTrackingModeNone];
hasUpdatedRegion=NO;
}
//MapKit Delegate Methods
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
NSLog(@"didUpdateUserLocation");
if(!hasUpdatedRegion)
{
hasUpdatedRegion=YES;
MKCoordinateSpan span=MKCoordinateSpanMake(0.3, 0.3);
MKCoordinateRegion currentRegion=MKCoordinateRegionMake(mapView.userLocation.coordinate, span);
[mapView setRegion:currentRegion];
}
}
-(void)mapView:(MKMapView *)mapView didChangeUserTrackingMode:(MKUserTrackingMode)mode animated:(BOOL)animated{
NSLog(@"didChangeTrackingMode");
}
我也有同樣的問題。 另一種方式......
- (void)viewDidLoad
{
self.mapView.userTrackingMode = YES;
}
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
self.mapView.userTrackingMode = NO;
}
首先,將userTrakingMode
設置為YES
跟蹤用戶的移動情況。
其次,在我已禁用跟蹤模式后,在將地圖更新到用戶位置didUpdateUserLocation
會觸發didUpdateUserLocation
。
這會阻止地圖再跟蹤用戶。
為什么不嘗試設置mapview區域,以便整個世界地圖顯示而不是特定位置(如你所說'Atantic ocean'),如果用戶不允許mapkit使用當前位置(i意味着在視圖中加載方法,設置地圖區域。),,如果他允許..然后根據用戶的坐標設置區域。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.