public static double CalculateDistances(this IEnumerable <Coordinate> points)
        {
            if (points == null)
            {
                return(0);
            }

            var items = points.ToArray();

            if (items.Length == 0)
            {
                return(0);
            }

            var last = items[0];
            var sum  = 0d;

            foreach (var point in items)
            {
                var len = GeoHelper.GetDistance(last.Longitude, last.Latitude, point.Longitude, point.Latitude);
                if (!double.IsNaN(len))
                {
                    sum += len;
                }
                last = point;
            }
            return(sum);
        }
Example #2
0
        /// <summary>
        /// 查找同方向的最近点位
        /// </summary>
        /// <param name="signalInfo"></param>
        /// <returns></returns>
        public MapPoint[] Search(CarSignalInfo signalInfo)
        {
            //无航向角(停车时)不搜索点位
            if (MapPoints.Length == 0 || !signalInfo.Gps.AngleDegrees.IsValidAngle() || signalInfo.CarState == CarState.Stop)
            {
                return(new MapPoint[0]);
            }

            var gps = signalInfo.Gps;
            //
            //搜索20米内同方向(相同15角度类)的所有点位
            var query = from a in MapPoints
                        where
                        a.PointType != MapPointType.Normal &&
                        GeoHelper.IsBetweenDiffAngle(a.Point.Angle, gps.AngleDegrees, 15) &&
                        (GeoHelper.GetDistance(a.Point.Longitude, a.Point.Latitude, gps.LongitudeDegrees, gps.LatitudeDegrees) <= 15)
                        select a;

            var items = query.ToArray();

            if (items.Any())
            {
                foreach (var _item in items)
                {
                    Logger.InfoFormat("搜索符合点:{0}-{1}-{2}-{3}", _item.Name, _item.Point.Longitude, _item.Point.Latitude, _item.Point.Angle);
                    Logger.InfoFormat("当前GPS:{0}-{1}-{2}", signalInfo.Gps.LongitudeDegrees, signalInfo.Gps.LatitudeDegrees, signalInfo.Gps.AngleDegrees);
                }
            }
            return(items);
            //return null;
        }
        public static double CalculateDistances(this IEnumerable <MapLinePoint> points, double longitude, double latitude)
        {
            var pointsDistance = CalculateDistances(points);

            if (points.Any())
            {
                var lastPoint = points.Last();
                var len       = GeoHelper.GetDistance(lastPoint.Longitude, lastPoint.Latitude, longitude, latitude);
                if (!double.IsNaN(len))
                {
                    pointsDistance += len;
                }
            }
            return(pointsDistance);
        }
Example #4
0
        public new void OnCameraChange(CameraPosition position)
        {
            // 156543.03392 * Math.cos(latLng.lat() * Math.PI / 180) / Math.pow(2, zoom)
//			var radius = 156543.03392 * System.Math.Cos(position.Target.Latitude * System.Math.PI / 180) / System.Math.Pow(2, position.Zoom);

            var bounds = this.NativeMap.Projection.VisibleRegion.LatLngBounds;

            var radiusInMeters = GeoHelper.GetDistance(bounds.Northeast.Latitude, bounds.Northeast.Longitude, bounds.Southwest.Latitude, bounds.Southwest.Longitude, true);

            var span = MapSpan.FromCenterAndRadius(
                new Position(bounds.Center.Latitude, bounds.Center.Longitude),
                Distance.FromMeters(radiusInMeters));

//				.WithZoom (position.Zoom);

            this.Map.VisibleRegion = span;
        }
Example #5
0
        public void TestNextPointAndDistanceCalculating()
        {
            Point a = new Point
            {
                Lat  = 52.458393,
                Long = 31.025021
            };
            Point b = new Point
            {
                Lat  = 52.459146,
                Long = 31.024851
            };

            double expectedDistance = 2;
            double bearing          = GeoHelper.GetBearing(a, b);

            Point nextPoint = GeoHelper.GetNextPoint(a, bearing, expectedDistance);

            double distance = GeoHelper.GetDistance(a, nextPoint);

            Assert.AreEqual(expectedDistance, Math.Round(distance));
        }
Example #6
0
        private void UpdateSelectedPin()
        {
            var formsMap       = (ExtendedMap)this.Element;
            var androidMapView = (MapView)Control;

            Marker selectedMarker = this.markers.FirstOrDefault(m => IsItem(formsMap.SelectedPin, m));

            if (selectedMarker != null)
            {
                var ne = androidMapView.Map.Projection.VisibleRegion.LatLngBounds.Northeast;
                var sw = androidMapView.Map.Projection.VisibleRegion.LatLngBounds.Southwest;

                var radius = GeoHelper.GetDistance(ne.Latitude, ne.Longitude, sw.Latitude, sw.Longitude, true);

                formsMap.MoveToRegion(MapSpan.FromCenterAndRadius(
                                          new Position(
                                              selectedMarker.Position.Latitude,
                                              selectedMarker.Position.Longitude),
                                          Distance.FromMeters(radius))
                                      );
                selectedMarker.ShowInfoWindow();
            }
        }
        //泸州特殊项目过滤完成了就不在自动触发
        protected override async Task MatchMapPointsAsync(CarSignalInfo signalInfo)
        {
            //只是一个条件
            if (Settings.PullOverStartFlage == false && Settings.EndExamByDistance && IsTriggerPullOver == false)
            {
                if (signalInfo.Distance >= Settings.ExamDistance)
                {
                    IsTriggerPullOver = true;
                    Logger.Info("里程达到三公里自动触发考试项目");
                    Messenger.Send <PullOverTriggerMessage>(new PullOverTriggerMessage());
                    return;
                }
            }
            //直线行驶路段忽略其它的考试项目
            if (ExamItems.Any(d => d.ItemCode == ExamItemCodes.StraightDriving && d.State != ExamItemState.Finished))
            {
                return;
            }

            var points = PointSearcher.Search(signalInfo);

            //对解除限速进行
            if (points.Any(d => d.PointType == MapPointType.UnfreezeSpeedLimit))
            {
                Messenger.Send(new EndSpeedLimitMessage());
            }
            var query = from p in points
                        where !ExamItems.Any(x => x.State != ExamItemState.Finished && x.TriggerPoint != null && x.TriggerPoint.PointType == p.PointType) &&
                        _mapTriggerPoints.All(x => x.Index != p.Index)
                        select p;

            foreach (var mapPoint in query)
            {
                var context = new ExamItemExecutionContext(Context);

                var item = DataService.AllExamItems.FirstOrDefault(x => x.MapPointType == mapPoint.PointType);
                if (item != null)
                {
                    if (Settings.PullOverStartFlage && InitPointList.Count > 0 && context.ExamMode == ExamMode.Examming)
                    {
                        Constants.IsExamMode_Luzhou = true;
                        if (item.MapPointType != MapPointType.TurnLeft && item.MapPointType != MapPointType.TurnRight)
                        {
                            //只报一次,除了左,右转
                            if (!FinishedPointList.Contains(item.MapPointType))
                            {
                                FinishedPointList.Add(item.MapPointType);
                            }
                            else
                            {
                                //播报过的项目,直接返回
                                return;
                            }
                        }
                        //////左转,右转,直行路口不过滤
                        ////if (FinishedPointList.Contains(item.MapPointType))
                        ////{
                        ////    //泸州过滤掉所有考试项目
                        ////    //if (item.ItemCode != ExamItemCodes.TurnLeft && item.ItemCode != ExamItemCodes.TurnRight &&
                        ////    //    item.ItemCode != ExamItemCodes.StraightThrough && item.ItemCode != ExamItemCodes.TurnRound
                        ////    //    && item.ItemCode != ExamItemCodes.SchoolArea && item.ItemCode != ExamItemCodes.BusArea && item.ItemCode != ExamItemCodes.PedestrianCrossing && item.ItemCode != ExamItemCodes.PedestrianCrossingHasPeople)
                        ////    {
                        ////        Logger.Info("跳过项目:" + item.ItemCode);
                        ////        continue;
                        ////    }
                        ////}

                        ////if (!FinishedPointList.Contains(item.MapPointType) && item.MapPointType != MapPointType.PullOver)
                        ////{
                        ////    FinishedPointList.Add(item.MapPointType);
                        ////    Logger.Info(item.MapPointType.ToString() + ":" + FinishedPointList.Count.ToString());
                        ////}
                    }
                    context.ItemCode = item.ItemCode;
                    ///超变会处理,相应的点位随机触发超车,变道,会车
                    if (item.ItemCode == ExamItemCodes.OvertakeChangeMeeting)
                    {
                        context.ItemCode = ExamItemCodes.GetRandomExamItemFromOvertakeChangeMeeting();
                    }
                    context.TriggerSource = ExamItemTriggerSource.Map;
                    context.Properties    = mapPoint.Properties;
                    context.TriggerPoint  = mapPoint;
                    Logger.InfoFormat("当前GPS:{0}-{1}-{2}", signalInfo.Gps.LatitudeDegrees, signalInfo.Gps.LongitudeDegrees, signalInfo.Gps.SpeedInKmh);
                    Logger.InfoFormat("点位GPS:{0}-{1}", mapPoint.Point.Latitude, mapPoint.Point.Longitude);
                    Logger.InfoFormat("相距位置:{0}米", GeoHelper.GetDistance(mapPoint.Point.Longitude, mapPoint.Point.Latitude, signalInfo.Gps.LongitudeDegrees, signalInfo.Gps.LatitudeDegrees));
                    Logger.InfoFormat("点位触发项目:{0}", item.ItemName);

                    await StartItemAsync(context, CancellationToken.None);
                }
                _mapTriggerPoints.Enqueue(mapPoint);
            }
            while (_mapTriggerPoints.Count > 2)
            {
                _mapTriggerPoints.Dequeue();
            }
        }
Example #8
0
        protected override async Task MatchMapPointsAsync(CarSignalInfo signalInfo)
        {
            //只是一个条件
            if (Settings.EndExamByDistance && IsTriggerPullOver == false)
            {
                if (signalInfo.Distance >= Settings.ExamDistance)
                {
                    IsTriggerPullOver = true;
                    Logger.Info("@@里程达到三公里自动触发考试项目");
                    Messenger.Send <PullOverTriggerMessage>(new PullOverTriggerMessage());
                    return;
                }
            }

            //直线行驶路段忽略其它的考试项目
            if (ExamItems.Any(d => d.ItemCode == ExamItemCodes.StraightDriving && d.State != ExamItemState.Finished))
            {
                return;
            }

            var points = PointSearcher.Search(signalInfo);

            //对解除限速进行
            if (points.Any(d => d.PointType == MapPointType.UnfreezeSpeedLimit))
            {
                Messenger.Send(new EndSpeedLimitMessage());
            }
            var query = from p in points
                        where !ExamItems.Any(x => x.State != ExamItemState.Finished && x.TriggerPoint != null && x.TriggerPoint.PointType == p.PointType) &&
                        _mapTriggerPoints.All(x => x.Index != p.Index)
                        select p;


            foreach (var mapPoint in query)
            {
                var context = new ExamItemExecutionContext(Context);

                var item = DataService.AllExamItems.FirstOrDefault(x => x.MapPointType == mapPoint.PointType);


                //其实最简单还是要在这里处理
                if (item != null)
                {
                    //排除语音点和起步
                    if (InitPointList.Count > 0 && !item.ItemName.Contains("点"))
                    {
                        if (!examingItem.Any(x => x.Equals(item.MapPointType)) && item.MapPointType != MapPointType.VehicleStarting)
                        {
                            examingItem.Enqueue(item.MapPointType);
                            FinishedPointList.Add(item.MapPointType);
                            Logger.Info("@@加入队列项目:{0}", item.ItemName);
                        }
                        if (examingItem.Count > 1)
                        {
                            examingItem.Dequeue();
                        }
                    }
                    context.ItemCode = item.ItemCode;
                    ///超变会处理,相应的点位随机触发超车,变道,会车
                    if (item.ItemCode == ExamItemCodes.OvertakeChangeMeeting)
                    {
                        context.ItemCode = ExamItemCodes.GetRandomExamItemFromOvertakeChangeMeeting();
                    }
                    context.TriggerSource = ExamItemTriggerSource.Map;
                    context.Properties    = mapPoint.Properties;
                    context.TriggerPoint  = mapPoint;
                    Logger.InfoFormat("当前GPS:{0}-{1}-{2}", signalInfo.Gps.LatitudeDegrees, signalInfo.Gps.LongitudeDegrees, signalInfo.Gps.SpeedInKmh);
                    Logger.InfoFormat("点位GPS:{0}-{1}", mapPoint.Point.Latitude, mapPoint.Point.Longitude);
                    Logger.InfoFormat("相距位置:{0}米", GeoHelper.GetDistance(mapPoint.Point.Longitude, mapPoint.Point.Latitude, signalInfo.Gps.LongitudeDegrees, signalInfo.Gps.LatitudeDegrees));
                    Logger.InfoFormat("点位触发项目:{0}", item.ItemName);

                    await StartItemAsync(context, CancellationToken.None);
                }
                _mapTriggerPoints.Enqueue(mapPoint);
            }
            while (_mapTriggerPoints.Count > 2)
            {
                _mapTriggerPoints.Dequeue();
            }
        }