سؤال

I am just working my way through the location services for the first time and everything appears to be working in that it correctly finds my location but I am having trouble extracting the coordinates.

The docs states that CLLocation has a "Coordinates" property and the compiler is happy with this piece of code. However at runtime the CLLocation only appears to return a string description.

I start the location manager

    _locationManager = new CLLocationManager ();
    _locationManager.DesiredAccuracy = 1000; 

    // handle the updated location method and update the UI
    _locationManager.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) => {
            UpdateLocation (e.Locations [e.Locations.Length - 1], _destinationLatitude, _destinationLongitude);
        };

    if (CLLocationManager.LocationServicesEnabled)
        _locationManager.StartUpdatingLocation ();

The event fires correctly

    static public void UpdateLocation (CLLocation current, Double destinationLat, Double destinationLng)
    {
        //Make the start pairing
        string start = current.Coordinate.Latitude.ToString() + "," + current.Coordinate.Longitude.ToString();

        //Make the destination pairing
        string destination = destinationLat.ToString() + "," + destinationLng.ToString();
    }

However the app just crashes out. Catching it on a breakpoint I see the following which only appears to have a description property that contains.

Description "<+50.58198902,-3.67661728> +/- 65.00m (speed -1.00 mps / course -1.00) @ 25/07/2013 13:11:28 British…" string

I can obviously extract the lat/lng from this text field but I get the feeling I shouldn't need to do this. Any help appreciated.

enter image description here

هل كانت مفيدة؟

المحلول

I moved the exact same code into a different controller and it worked fine. The only difference between the two controllers was that the failing controller was using the monotouch dialog reflection api to bind the screen elements. I can't see why this would make any difference but it is the only difference between the two controllers. Everything is working now, I will try to reproduce in a smaller sample if I get the time.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top