简体   繁体   中英

Xamarin Forms Maps - showing current location on iOS

In Xamarin Forms, does the IsShowingUser property of Xamarin.Forms.Maps work for iOS?

I can get every aspect of my map to work on both Android and iOS, but the current location 'blue dot' does not show on iOS.

I'm setting this in shared code in the PCL project, just after successfully asking for permission to use location.

var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location);
            if (status != PermissionStatus.Granted)
            {
                var results = await CrossPermissions.Current.RequestPermissionsAsync(new[] { Permission.Location });
                status = results[Permission.Location];
            }

            if (status == PermissionStatus.Granted)
            {
                MyMap.IsShowingUser = true;
            }

thanks

I can get every aspect of my map to work on both Android and iOS, but the current location 'blue dot' does not show on iOS.

It is because the map doesn't locate the current user location at that time, you can use Xam.Plugin.Geolocator to get your current location, and move the map to it.

var locator = CrossGeolocator.Current;
var position = await locator.GetPositionAsync(TimeSpan.FromSeconds(10));
map.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(position.Latitude, position.Longitude),
                                                     Distance.FromMiles(1)));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM