How to get the current location in Xamarin iOS widget ?
Does anyone have idea reagarding this?
Implementing location service in extension app is no difference with containing app.
Firstly modify your extension app's info.plist. Add NSLocationAlwaysAndWhenInUseUsageDescription and NSLocationWhenInUseUsageDescription keys for iOS 11+.
Secondly we can initialize the locationManager in the TodayViewController's ViewDidLoad event:
public override void ViewDidLoad()
PreferredContentSize = new CGSize(0, 240);
locationManager = new CLLocationManager();
locationManager.Delegate = new LocationDelegate();
At last you can get the location information in the Delegate:
public class LocationDelegate: CLLocationManagerDelegate
public override void LocationsUpdated(CLLocationManager manager, CLLocation locations)
CLLocation location = locations.FirstOrDefault();
var latitude = location.Coordinate.Latitude;
var longitude = location.Coordinate.Longitude;
Here is a sample for you referring to. Run the extension project part to see the effect.
Thanks for your rply. I fixed that issue by doing some changes in the Extension level..
@SmartMan Glad you solved it. If you feel this helpful for you. Please mark it to close this thread.
Xamarin Inc., as a wholly-owned Microsoft subsidiary acting as a separate legal entity, adheres to the Microsoft Privacy Statement: Privacy & cookies