Пример #1
0
        public void Converter(BaiduMaps.Map map, double lat, double lng)
        {
            try
            {
                //初始化坐标转换工具类,指定源坐标类型和坐标数据
                CoordinateConverter converter = new CoordinateConverter()
                                                .From(CoordinateConverter.CoordType.Gps)
                                                .Coord(new Com.Baidu.Mapapi.Model.LatLng(lat, lng));

                //desLatLng 转换后的坐标
                var lct = converter.Convert();

                if (map != null && lct != null)
                {
                    if (lct.Latitude > 0 && lct.Longitude > 0)
                    {
                        map.Center = new Coordinate(lct.Latitude, lct.Longitude);
                        map.SendStatusChanged(lct.Latitude, lct.Longitude);
                    }
                }

                if (lct != null && lct.Latitude > 0 && lct.Longitude > 0)
                {
                    GlobalSettings.UpdatePoi(lct.Latitude, lct.Longitude);
                }
            }
            catch (Exception) { }
        }
Пример #2
0
        public async Task UpdateCenter(BaiduMaps.Map map)
        {
            try
            {
                var locationManager = (LocationManager)MainActivity.Instance.GetSystemService(Context.LocationService);
                //判断GPS是否开启,没有开启,则开启
                if (!locationManager.IsProviderEnabled(LocationManager.GpsProvider))
                {
                    var toast = Toast.MakeText(Android.App.Application.Context, "你的位置服务没有开启,请打开GPS", ToastLength.Short);
                    toast.SetGravity(GravityFlags.Center, 0, 0);
                    toast.Show();
                }
                else
                {
                    var locp = await Permissions.RequestAsync <Permissions.LocationWhenInUse>();

                    if (locp != PermissionStatus.Granted)
                    {
                        var toast = Toast.MakeText(Android.App.Application.Context, "你的位置服务没有开启,请打开GPS", ToastLength.Short);
                        toast.SetGravity(GravityFlags.Center, 0, 0);
                        toast.Show();
                    }
                    else
                    {
                        var request  = new GeolocationRequest(GeolocationAccuracy.Best, TimeSpan.FromSeconds(2));
                        var location = await Geolocation.GetLocationAsync(request, Cts.Token);

                        if (location != null)
                        {
                            Converter(map, location.Latitude, location.Longitude);
                        }
                    }
                }
            }
            catch (FeatureNotEnabledException)
            {
                Cts.Token.ThrowIfCancellationRequested();
                Cts.Cancel();
            }
            catch (FeatureNotSupportedException)
            {
                Cts.Token.ThrowIfCancellationRequested();
                Cts.Cancel();
            }
            catch (PermissionException)
            {
                Cts.Token.ThrowIfCancellationRequested();
                Cts.Cancel();
            }
            catch (Exception)
            {
                Cts.Token.ThrowIfCancellationRequested();
                Cts.Cancel();
            }
        }
Пример #3
0
        public async Task UpdateCenter(BaiduMaps.Map map, Action action)
        {
            await UpdateCenter(map);

            action?.Invoke();
        }