public Task<HeritageProperties.PCL.Location> GetLocation() { // check to see if location is found bool locationFound = false; var ret = new HeritageProperties.PCL.Location(); // create the location manager passing in the callback parameter InitializeLocationManager((loc) => { if (loc != null) { ret = new HeritageProperties.PCL.Location() { Latitude = loc.Latitude, Longitude = loc.Longitude }; } locationFound = true; }); // run the task return Task.Run(async () => { // wait till done while (!locationFound) await Task.Delay(200); // stop udpating the location _locationManager.RemoveUpdates(_listener); // return the location return ret; }); }
public Task<Location> GetLocation() { manager.StartUpdatingLocation(); return Task.Run(async () => { var ret = new Location(); var locationFound = false; // create the locator manager.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) => { if (e.Locations.Length > 0) { ret = new Location() { Latitude = e.Locations[0].Coordinate.Latitude, Longitude = e.Locations[0].Coordinate.Longitude }; } locationFound = true; }; manager.Failed += (object sender, NSErrorEventArgs e) => { locationFound = true; }; // wait till done while (!locationFound) await Task.Delay(200); // stop udpating the location manager.StopUpdatingLocation(); // return the location return ret; }); }
public Task <HeritageProperties.PCL.Location> GetLocation() { // check to see if location is found bool locationFound = false; var ret = new HeritageProperties.PCL.Location(); // create the location manager passing in the callback parameter InitializeLocationManager((loc) => { if (loc != null) { ret = new HeritageProperties.PCL.Location() { Latitude = loc.Latitude, Longitude = loc.Longitude }; } locationFound = true; }); // run the task return(Task.Run(async() => { // wait till done while (!locationFound) { await Task.Delay(200); } // stop udpating the location _locationManager.RemoveUpdates(_listener); // return the location return ret; })); }