Closed davidbuckleyni closed 4 years ago
I am trying to update the map I have requested permission and I am using andriod Gelocation.
double lat=0.00; double lng=0.00; var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location); if (status != PermissionStatus.Granted) { if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Location)) { await DisplayAlert("Need location", "Gunna need that location", "OK"); } var results = await CrossPermissions.Current.RequestPermissionsAsync(Permission.Location); status = results[Permission.Location]; } if (status == PermissionStatus.Granted) { ILocation loc = DependencyService.Get<ILocation>(); loc.locationObtained += (object ss, ILocationEventArgs ee) => { lat = ee.lat; lng = ee.lng; loc.ObtainMyLocation(); loc = null; lbllat.Text = lat.ToString(); lbllong.Text = lng.ToString(); }; lbllat.Text = lat.ToString(); lbllong.Text = lng.ToString(); loc.ObtainMyLocation(); loc = null; await Task.Delay(4000); Position position = new Position(lat, lng); lbllat.Text = lat.ToString(); lbllong.Text = lng.ToString(); map.Pins.Add(_pinTokyo2); }
My Andriod Google GetMyLocation
public class LocationEventArgs : EventArgs, ILocationEventArgs { public double lat { get; set; } public double lng { get; set; } } public class GetMyLocation : Java.Lang.Object, ILocation, ILocationListener { public event EventHandler<ILocationEventArgs> locationObtained; public void ObtainMyLocation() { LocationManager lm = (LocationManager)Forms.Context.GetSystemService(Context.LocationService); lm.RequestLocationUpdates(LocationManager.NetworkProvider, 0, 0, this); } public void OnLocationChanged(Location location) { if (location != null) { LocationEventArgs args = new LocationEventArgs(); args.lat = location.Latitude; args.lng = location.Longitude; locationObtained(this, args); } } public void OnProviderDisabled(string provider) { } public void OnProviderEnabled(string provider) { } public void OnStatusChanged(string provider, [GeneratedEnum] Availability status, Bundle extras) { } } }
I have a plan to support LocationSource.
LocationSource
https://developers.google.com/android/reference/com/google/android/gms/maps/LocationSource#nested-class-summary
I am trying to update the map I have requested permission and I am using andriod Gelocation.
My Andriod Google GetMyLocation