예제 #1
0
        static ShapeHolder DetermineClosestPoint(string trip_id, double test_lat, double test_lon)
        {
            double positionTolerance = Convert.ToDouble(ConfigurationManager.AppSettings.Get("VehiclePositionTolerance"));
            // get shapes
            List <Shapes> shapes = db.Database
                                   .SqlQuery <Shapes>("ShapesGetByTripId @trip_id",
                                                      new SqlParameter("@trip_id", trip_id))
                                   .ToList();

            List <ShapeHolder> shapeHolders = new List <ShapeHolder>();

            foreach (Shapes shape in shapes)
            {
                double dist = CalculateClosestPoint(test_lat, test_lon, shape.shape_pt_lat, shape.shape_pt_lon);
                if (dist <= positionTolerance)
                {
                    shapeHolders.Add(new ShapeHolder(shape.shape_pt_lat, shape.shape_pt_lon, dist));
                }
            }

            ShapeHolder shapeHolder = new ShapeHolder(0, 0, 0);

            if (shapeHolders.Count > 0)
            {
                shapeHolder = shapeHolders.OrderBy(o => o.shape_distance).First();
            }

            return(shapeHolder);
        }
예제 #2
0
        static int doGlobeCall(string mobileNumber, string accessToken, RTTripUpdates tripUpdate)
        {
            // call globe api
            JToken jsonReturn = GlobeLabs.LocateDevice(mobileNumber, accessToken);

            string processResult = "";

            if (((JProperty)jsonReturn.First).Name == "error")
            {
                processResult = ((JProperty)jsonReturn.First).Value.ToString();
                return(0);
            }
            else if (((JProperty)jsonReturn.First).Name == "terminalLocationList")
            {
                globe_lbs lbs       = JsonConvert.DeserializeObject <globe_lbs>(jsonReturn.ToString());
                double    latitude  = Convert.ToDouble(lbs.terminalLocationList.terminalLocation.currentLocation.latitude);
                double    longitude = Convert.ToDouble(lbs.terminalLocationList.terminalLocation.currentLocation.longitude);

                ShapeHolder sh = DetermineClosestPoint(tripUpdate.trip_id, latitude, longitude);
                //ShapeHolder sh = DetermineClosestPoint(tripUpdate.trip_id, 14.58793, 121.05693);

                if (sh.shape_pt_lat > 0)
                {
                    // save data to rt vehicle position
                    RTVehiclePositions vp = new RTVehiclePositions();

                    vp.route_id     = tripUpdate.route_id;
                    vp.trip_id      = tripUpdate.trip_id;
                    vp.direction_id = tripUpdate.direction_id;
                    vp.start_date   = tripUpdate.start_date;
                    vp.start_time   = tripUpdate.start_time;
                    vp.latitude     = sh.shape_pt_lat;
                    vp.longitude    = sh.shape_pt_lon;
                    vp.timestamp    = (long)Functions.ToEpoch(DateTime.UtcNow);

                    db.RTVehiclePositions.Add(vp);
                    return(1);
                }
            }

            return(0);
        }