2011-04-15 100 views
2

作爲標題,我對如何使用MonoTouch捕獲地圖以及如何獲取位置感到困惑。如步驟:MonoTouch獲取位置和捕獲地圖圖像,如聯繫人

CLLocationManager locationManager = new CLLocationManager(); 
locationManager.UpdatedLocation += UpdatedLocationEvent; 
locationManager.Delegate = new MyLocationDelegate(); 

locationManager.StartUpdatingLocation(); 

    class MyLocationDelegate : CLLocationManagerDelegate 
{ 
    public MyLocationDelegate() : base() 
    { 
    } 

    public override void UpdatedLocation (CLLocationManager manager, CLLocation newLocation, CLLocation oldLocation) 
    { 
     Console.WriteLine ("newLocation " + newLocation.VerticalAccuracy + " " + newLocation.HorizontalAccuracy); 
     Console.WriteLine ("oldLocation " + oldLocation.VerticalAccuracy + " " + oldLocation.HorizontalAccuracy); 
    } 

    public override void Failed (CLLocationManager manager, NSError error) 
    { 
     Console.WriteLine ("Failed to find location"); 
    } 
} 

它不起作用。請幫幫我。

+0

你需要解釋「不工作」。它會崩潰嗎?你有任何錯誤?什麼是或沒有發生?您應該使用CLLocation的座標屬性或水平/垂直精度。 – Jason 2011-04-15 12:26:09

+0

沒有崩潰,沒有錯誤,但沒有工作,我無法獲得當前位置。 – 2011-04-18 01:37:34

回答

3

您還沒有配置的那種,你得到的,你缺少這樣一行事件:

locationManager = new CLLocationManager() { 
    DesiredAccuracy = CLLocation.AccuracyBest, 
    Delegate = new MyCLLocationManagerDelegate (callback), 
    DistanceFilter = 1000f 
}; 
if (CLLocationManager.LocationServicesEnabled) 
    locationManager.StartUpdatingLocation();