我似乎有許多相關的問題,這裏發佈的有關MKMapView
的許多人。而不是不能得到它放大和顯示當前的位置,我似乎無法得到它停止這樣做。這裏是發生了什麼:防止MKMapView不斷重新縮放和重新定位到用戶位置
- 我啓動的應用程序
- 的的MKMapView顯示了我的位置,並以藍點
- 我用我的手指
- 幾秒鐘後,的MKMapView縮小和遠在地圖上突然放大早在到中心對我的當前位置再次
我試圖告訴我的CLLocationManager
到stopUpdatingLocation
(沒有任何影響,因爲一個MKMapView
知道如何使用CoreLocation
),我試過告訴MKMapView
到setShowsUserLocation:NO
(根本不顯示藍點,這不是我想要的)。我甚至試圖消除我的CLLocationManager
(沒有效果)。是什麼原因導致這種情況,我該如何阻止它?
是的,我做的設置位置管理的精度和距離-loadView
。我不執行-mapViewDidFinishLoadingMap
:。這是我實現
-locationManager:didUpdateToLocation:fromLocation:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
// How many seconds ago was this new location created?
NSTimeInterval t = [[newLocation timestamp] timeIntervalSinceNow];
// CLLocationManagers will return the last found location of the device first,
// you don't want that data in this case. If this location was made more than 3
// minutes ago, ignore it.
if (t < -180)
{
// This is cached data, you don't want it, keep looking
return;
}
[locationManager stopUpdatingLocation];
}
我覺得這是定心你問一下,@Anna·卡列尼娜:
- (void)mapView:(MKMapView *)mv didUpdateUserLocation:(MKUserLocation *)u
{
CLLocationCoordinate2D loc = [u coordinate];
// Display the region 500 meters square around the current location
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(loc, 500, 500);
[mv setRegion:region animated:YES];
}
你在做什麼?在'mapView:didUpdateUserLocation:'?你可以發佈該代碼嗎? – Anna
每次用戶位置更改或獲取新讀數時,都會調用didUpdateUserLocation方法。您可以添加一個bool ivar,您可以在該方法中進行檢查/設置,以便只進行一次對中_OR_,您可以根據u.location.horizontalAccuracy或u.location.timestamp有條件地進行居中。 – Anna
好的,這是有道理的,但是...我現在有-mapView:didUpdateUserLocation:有條件地集中,如果u.location.horizontalAccuracy> locationManager.desiredAccuracy,它仍然在發生。如果我扭轉了這種情況,我沒有獲得初始縮放。 – DJHoward