コード例 #1
0
        public void OnReceiveLocation(BDLocation location)
        {
            if (stopped)
            {
                return;
            }

            //Debug.WriteLine("LocType: " + location.LocType);
            switch (location.LocType)
            {
            default: break;

            case BDLocation.TypeServerError:
            case BDLocation.TypeNetWorkException:
            case BDLocation.TypeCriteriaException:
                break;

            case BDLocation.TypeGpsLocation:
            case BDLocation.TypeNetWorkLocation:
            case BDLocation.TypeOffLineLocation:
                BMap.MyLocationData loc = new BMap.MyLocationData.Builder()
                                          .Accuracy(location.Radius)
                                          .Direction(location.Direction)
                                          .Latitude(location.Latitude)
                                          .Longitude(location.Longitude)
                                          .Build();
                mapView.Map.SetMyLocationData(loc);

                LocationUpdated?.Invoke(this, new LocationUpdatedEventArgs
                {
                    //Coordinate = new Coordinate(loc.Latitude, loc.Longitude),
                    Direction  = location.Direction,
                    Accuracy   = location.HasRadius ? location.Radius : double.NaN,
                    Altitude   = location.HasAltitude ? location.Altitude : double.NaN,
                    Satellites = location.SatelliteNumber,
                    Type       = location.LocTypeDescription
                });
                return;
            }

            Failed?.Invoke(this, new LocationFailedEventArgs(location.LocType.ToString()));
        }
コード例 #2
0
        /// <summary>
        /// 实现位置监听,实时缓存我的位置
        /// </summary>
        /// <param name="location"></param>
        public void OnReceiveLocation(BDLocation location)
        {
            if (stopped)
            {
                return;
            }

            System.Diagnostics.Debug.WriteLine("LocType: " + location.LocType);

            switch (location.LocType)
            {
            default: break;

            case BDLocation.TypeServerError:
            {
                System.Diagnostics.Debug.Print("服务端网络定位失败,可以反馈IMEI号和大体定位时间到[email protected],会有人追查原因");
            }
            break;

            case BDLocation.TypeNetWorkException:
            {
                System.Diagnostics.Debug.Print("网络不同导致定位失败,请检查网络是否通畅");
            }
            break;

            case BDLocation.TypeCriteriaException:
            {
                System.Diagnostics.Debug.Print("无法获取有效定位依据导致定位失败,一般是由于手机的原因,处于飞行模式下一般会造成这种结果,可以试着重启手机");
            }
            break;

            case BDLocation.TypeGpsLocation:
            case BDLocation.TypeNetWorkLocation:
            case BDLocation.TypeOffLineLocation:
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("time : ");
                sb.Append(location.Time);
                sb.Append("\nerror code : ");
                sb.Append(location.LocType);
                sb.Append("\nlatitude : ");
                sb.Append(location.Latitude);
                sb.Append("\nlontitude : ");
                sb.Append(location.Longitude);
                sb.Append("\nradius : ");
                sb.Append(location.Radius);

                System.Diagnostics.Debug.Print(sb.ToString());

                BMap.MyLocationData loc = new BMap.MyLocationData.Builder()
                                          .Accuracy(location.Radius)
                                          .Direction(location.Direction)
                                          .Latitude(location.Latitude)
                                          .Longitude(location.Longitude)
                                          .Build();

                mapView.Map.SetMyLocationData(loc);

                ///位置更新
                LocationUpdated?.Invoke(this, new LocationUpdatedEventArgs
                    {
                        Coordinate = new Coordinate(loc.Latitude, loc.Longitude),
                        Direction  = location.Direction,
                        Accuracy   = location.HasRadius ? location.Radius : double.NaN,
                        Altitude   = location.HasAltitude ? location.Altitude : double.NaN,
                        Satellites = location.SatelliteNumber,
                        Type       = location.LocTypeDescription,
                        Province   = location.Province,
                        City       = location.City,
                        District   = location.District,
                        Street     = location.Street,
                        Address    = location.AddrStr
                    });
                return;
            }
            }

            Failed?.Invoke(this, new LocationFailedEventArgs(location.LocType.ToString()));
        }