MonoTouch得到位置&捕获地图图像,如联系人

时间:2011-04-15 06:09:49

标签: google-maps xamarin.ios location contacts

作为标题,我对如何使用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");
    }
}

它不起作用。请帮帮我。

1 个答案:

答案 0 :(得分:3)

你还没有配置你得到的事件类型,你错过了这样的一行:

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