Xamarin Forms Maps-在iOS上显示当前位置 [英] Xamarin Forms Maps - showing current location on iOS

查看:74
本文介绍了Xamarin Forms Maps-在iOS上显示当前位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Xamarin Forms中,Xamarin.Forms.Maps的IsShowingUser属性是否适用于iOS?

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

我可以使地图的各个方面都可以在Android和iOS上使用,但是当前位置蓝点"在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.

在成功请求使用位置的权限之后,我正在PCL项目的共享代码中进行设置.

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;
            }

谢谢

推荐答案

我可以使地图的各个方面都可以在Android和iOS上使用,但是当前位置蓝点"在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.

这是因为当时地图未找到当前用户位置,因此可以使用 Xam.Plugin .Geolocator 获取您的当前位置,然后将地图移至该位置.

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)));

这篇关于Xamarin Forms Maps-在iOS上显示当前位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆