2012-07-17 53 views
0

我正在製作一個在森林中有一系列路徑的應用程序。全球定位系統(GPS)現在將會關閉幾十米,因此我正在嘗試編寫一些代碼,將用戶位置視圖「捕捉」到蹤跡(用戶可能在哪裏)。重新定位MKMapView的userLocationView?

我有一些代碼工作,掃描附近的路徑,確定用戶的可能位置,並獲取CLLocationCoordinate2D它。

現在我需要將該位置應用於userLocationView。我認爲這會工作,但它似乎並不:

userLocationAnnotation.coordinate = myDerivedCoordinate; 

我知道我大概可以創建自己的註解,但我想避免,如果可能的。

回答

1

MapView直接從CLLocationManager獲取用戶位置,並且沒有記錄的方式來攔截此交互。這樣做會比添加自己的註釋更多的工作,並導致應用程序拒絕。此外,重新定義系統提供的正確信息是沒有意義的。這就是爲什麼mapView.userLocation是帶有隻讀位置屬性的MKUserLocation

所以,你必須創建自己的,大致爲:

  • mapView.showsUserLocation = false;
  • 創建並啓動一個位置管理

    self.locationManager = [CLLocationManager new]; self.locationManager.delegate = self; [self.locationManager startUpdatingLocation];

  • 添加/替換自己的藍點註釋來自CLLocationManagerDelegatelocationManager:didUpdateToLocation:fromLocation:

你可以用UIKit-Artwork-Extractor獲得藍點圖形(可能是脈動的圓圈)。對於脈動效果,請將MKAnnotationView a UIImageView與不同的幀相加,或者取一個圓並使用UIView animateWithDurationCGAffineTransformMakeScale用於view.transform屬性。

+0

這是我需要聽到的,謝謝! – jarcoal 2012-07-17 23:04:20