Example #1
0
        public static IPassenger GetInstanceWithId(string name, GeoLoc destination)
        {
            var newPassengerWithId = new Passenger(idSeed, name, destination);

            idSeed = idSeed * 2;
            return(newPassengerWithId);
        }
            protected override void MoveCamera(GeoLoc mapCenter)
            {
                var map          = _mapFragment.Map;
                var cameraUpdate = CameraUpdateFactory.NewLatLngZoom(Utils.GetLatLng(mapCenter), 15);

                map.MoveCamera(cameraUpdate);
            }
        /// <summary>
        /// Create and return a new SAMPLE based on the index in the mTempList
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        private SAMPLE BuildNewSample(int index)
        {
            SAMPLE newSample = new SAMPLE();
            // Build new sample
            GeoLoc     point1        = new GeoLoc(mTempList[index - 1].LAT, mTempList[index - 1].LON);
            GeoLoc     point2        = new GeoLoc(mTempList[index].LAT, mTempList[index].LON);
            double     newPointSlope = (mTempList[index - 1].SLOPE + mTempList[index].SLOPE) / 2;
            double     newPointSpeed = (mTempList[index - 1].KPH + mTempList[index].KPH) / 2;
            GeoLocMath geoLocM1      = new GeoLocMath(point1, point2);
            GeoLoc     newPoint      = geoLocM1.CalcMidPoint();

            geoLocM1.point1 = newPoint;
            geoLocM1.point2 = point1;
            double newdistanceTravelled = geoLocM1.CalcDistanceBetweenGeoLocations() + mTempList[index - 1].KM;

            // Create new sample and add data from above
            newSample = new SAMPLE()
            {
                SECS  = 999999, //insertPosition,
                KM    = newdistanceTravelled,
                KPH   = newPointSpeed,
                ALT   = (mTempList[index].ALT + mTempList[index - 1].ALT) / 2,
                LAT   = newPoint.Latitude,
                LON   = newPoint.Longitude,
                SLOPE = newPointSlope
            };
            return(newSample);
        }
Example #4
0
        //step 2:

        private void CheckWithin5kmRadius(string address)
        {
            // Find the START LOCATION (entered by the user)
            GeoLoc startLocation = Geocoder.LocateGoogle(address + "," + ConfigurationManager.AppSettings["Country"]) ?? new GeoLoc();
            SortedList <Double, Supplier> nearest = new SortedList <double, Supplier>();

            List <Supplier> doctors = entity.Suppliers.Where(i => i.IsNetworkSupplier.Value && i.IdDiscipline == 10 || i.IdDiscipline == 11).ToList();

            foreach (Supplier o in doctors)
            {
                GeoLoc location = new GeoLoc
                {
                    Lat = o.Latitude.Value,
                    Lon = o.Longitude.Value
                };
                if (location.Lat != 0 && location.Lon != 0)
                {
                    Double distance = Distance(startLocation, location);
                    if (distance > 0 && distance <= 15)
                    {
                        Console.WriteLine("Doctor found within 15 km");
                    }
                }
            }

            if (startLocation.Lon != 0)
            {   // starting point was resolved
            }
        }
        private byte[] RotateAndScale(byte[] photo, out GeoLoc geoLoc)
        {
            using (var image = Image.Load(photo))
            {
                try
                {
                    geoLoc = GeoLoc.FromExif(image.MetaData);
                }
                catch
                {
                    geoLoc = null;
                }

                image.Mutate(x => x
                             .AutoOrient()
                             .Resize(new ResizeOptions()
                {
                    Size = new SixLabors.Primitives.Size(1024, 768), Mode = ResizeMode.Max
                }));

                var ms = new MemoryStream();
                image.SaveAsJpeg(ms);
                // return Convert.ToBase64String(ms.ToArray());
                return(ms.ToArray());
            }
        }
 public MapPointsActivityBase(int layoutId, int mapPointTextId, GeoLoc mapCentre)
 {
     _layoutId          = layoutId;
     _wRoutesMapperImpl = new WalkingRoutesMapperImpl(this)
     {
         MapCentre = mapCentre, MapPointTextId = mapPointTextId
     };
 }
 void OnCurLocChanged(object sender, DynProp <LocInfo> .EvtArgs e)
 {
     if ((LastLoc != null) && (              // if not the first update and
             !HasAccuracyImproved(e.NewValue.Accuracy) ||
             CommonUtils.GeoDistance(LastLoc, e.NewValue.Loc) < VICINITY_THRESHOLD))
     {
         return;
     }
     LastLoc       = e.NewValue.Loc;
     _lastAccuracy = e.NewValue.Accuracy ?? int.MaxValue;
 }
Example #8
0
        public Startup(IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(env.ContentRootPath)
                          .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                          .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
                          .AddEnvironmentVariables();

            Configuration = builder.Build();

            GeoLoc geoLoc = new GeoLoc();
        }
Example #9
0
        public IActionResult CadastrarLocalizacao(GeoLoc localizacao)
        {
            try
            {
                String TipoDeUsuario = (HttpContext.User.Claims.First
                                            (c => c.Type == ClaimTypes.Role).Value);

                GeolocalizacaoRepository.cadastrarLoc(localizacao.latitude, localizacao.longitude, TipoDeUsuario);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(new { message = "erro: " + ex }));
            }
        }
Example #10
0
        private static string GetRequestUrl(GeoLoc origin, List <GeoLoc> destinations)
        {
            const string API_URL = "https://maps.googleapis.com/maps/api/distancematrix/json?";
            //const string API_KEY = "AIzaSyBhbo2sRdTJVEJ47Q4GTq4tMFslExcFOOs";
            const string API_KEY = "AIzaSyA2VMVwB8SO-vEt60C7-aSZj6V4DQdrMoI";

            string destinationsParam = $"{destinations[0].Latitude},{destinations[0].Longitude}";

            for (int i = 1; i < destinations.Count; i++)
            {
                destinationsParam += $"|{destinations[i].Latitude},{destinations[i].Longitude}";
            }

            string getReqUrl = $"{API_URL}origins={origin.Latitude},{origin.Longitude}&destinations={destinationsParam}&key={API_KEY}";

            return(getReqUrl);
        }
Example #11
0
        internal GeoLoc GetMyGeoLocation()
        {
            var geoLoc = new GeoLoc();

            try
            {
                //create a request to geoiptool.com
                var request = WebRequest.Create(new Uri("http://geoiptool.com/data.php")) as HttpWebRequest;

                if (request != null)
                {
                    //set the request user agent
                    request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727)";

                    //get the response
                    using (var webResponse = (HttpWebResponse)request.GetResponse())
                    {
                        using (var reader = new StreamReader(webResponse.GetResponseStream()))
                        {
                            //get the XML document
                            var doc = new XmlDocument();
                            doc.Load(reader);

                            //now we parse the XML document
                            var nodes  = doc.GetElementsByTagName("marker");
                            var marker = (XmlElement)nodes[0];

                            //get the data and return it
                            geoLoc.City      = marker.GetAttribute("city");
                            geoLoc.Country   = marker.GetAttribute("country");
                            geoLoc.Code      = marker.GetAttribute("code");
                            geoLoc.Host      = marker.GetAttribute("host");
                            geoLoc.Ip        = marker.GetAttribute("ip");
                            geoLoc.Latitude  = marker.GetAttribute("lat");
                            geoLoc.Lognitude = marker.GetAttribute("lng");

                            return(geoLoc);
                        }
                    }
                }
            }
            catch {}

            return(new GeoLoc());
        }
Example #12
0
        public static async Task <List <Distance> > GetAll(GeoLoc origin, List <IPassenger> passengers)
        {
            var result = new List <Distance>();

            string url = GetRequestUrl(origin, passengers.Select(p => p.Destination).ToList());

            var response = await GetDistanceResponse(url);

            for (int i = 0; i < passengers.Count; i++)
            {
                var distance = new Distance {
                    From   = Vehicle.ORIGIN,
                    To     = passengers[i].ID,
                    Meters = response.Rows[0].Elements[i].Distance.Value
                };

                result.Add(distance);
            }

            for (int i = 0; i < passengers.Count; i++)
            {
                var passenger = passengers[i];

                var otherPassengers = passengers.Where(p => !p.Equals(passenger)).ToList();

                string url2 = GetRequestUrl(passenger.Destination, otherPassengers.Select(p => p.Destination).ToList());

                var response2 = await GetDistanceResponse(url2);

                for (int j = 0; j < otherPassengers.Count; j++)
                {
                    var distance = new Distance
                    {
                        From   = passenger.ID,
                        To     = otherPassengers[j].ID,
                        Meters = response2.Rows[0].Elements[j].Distance.Value
                    };

                    result.Add(distance);
                }
            }

            return(result);
        }
        internal GeoLoc GetMyGeoLocation()
        {
            var geoLoc = new GeoLoc();
            try
            {
                //create a request to geoiptool.com
                var request = WebRequest.Create(new Uri("http://geoiptool.com/data.php")) as HttpWebRequest;

                if (request != null)
                {
                    //set the request user agent
                    request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727)";

                    //get the response
                    using (var webResponse = (HttpWebResponse)request.GetResponse())
                    {
                        using (var reader = new StreamReader(webResponse.GetResponseStream()))
                        {
                            //get the XML document
                            var doc = new XmlDocument();
                            doc.Load(reader);

                            //now we parse the XML document
                            var nodes = doc.GetElementsByTagName("marker");
                            var marker = (XmlElement) nodes[0];

                            //get the data and return it
                            geoLoc.City = marker.GetAttribute("city");
                            geoLoc.Country = marker.GetAttribute("country");
                            geoLoc.Code = marker.GetAttribute("code");
                            geoLoc.Host = marker.GetAttribute("host");
                            geoLoc.Ip = marker.GetAttribute("ip");
                            geoLoc.Latitude = marker.GetAttribute("lat");
                            geoLoc.Lognitude = marker.GetAttribute("lng");

                            return geoLoc;
                        }
                    }
                }
            }
            catch{}

            return new GeoLoc();
        }
        /// <summary>
        /// Add a new point between 2 adjacent ones
        /// </summary>
        private void  AddNewPoint(
            ref int thisOldRideCnt,
            ref int thisNewRideCnt,
            ref int pointsAdded,
            ref GoldenCheetahRide thisOldRide,
            ref GoldenCheetahRide thisNewRide,
            ref string fullPath)
        {
            // Add new sample
            GeoLoc point1        = new GeoLoc(thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].LAT, thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].LON);
            GeoLoc point2        = new GeoLoc(thisOldRide.RIDE.SAMPLES[thisOldRideCnt].LAT, thisOldRide.RIDE.SAMPLES[thisOldRideCnt].LON);
            double newPointSlope = (thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].SLOPE + thisOldRide.RIDE.SAMPLES[thisOldRideCnt].SLOPE) / 2;
            double newPointSpeed = (thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].KPH + thisOldRide.RIDE.SAMPLES[thisOldRideCnt].KPH) / 2;

            GeoLocMath geoLocM1 = new GeoLocMath(point1, point2);
            GeoLoc     newPoint = geoLocM1.CalcMidPoint();

            geoLocM1.point1 = newPoint;
            geoLocM1.point2 = point1;
            double newdistanceTravelled = geoLocM1.CalcDistanceBetweenGeoLocations() + thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].KM;
            // Create new sample and add data from above
            SAMPLE newSample = new SAMPLE()
            {
                SECS  = 999, //insertPosition,
                KM    = newdistanceTravelled,
                KPH   = newPointSpeed,
                ALT   = (thisOldRide.RIDE.SAMPLES[thisOldRideCnt].ALT + thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].ALT) / 2,
                LAT   = newPoint.Latitude,
                LON   = newPoint.Longitude,
                SLOPE = newPointSlope
            };

            // Insert new point in ride
            thisNewRide.RIDE.SAMPLES.Add(newSample);
            testSegment.Add(newSample);
            SaveLineToTxt(newSample, fullPath, -1, thisNewRideCnt);
            thisNewRideCnt += 1;

            pointsAdded++;
        }
Example #15
0
        protected List <GeoLoc> DecodePoly(string encoded)
        {
            var poly = new List <GeoLoc>();
            int index = 0, len = encoded.Length;
            int lat = 0, lng = 0;

            while (index < len)
            {
                int b, shift = 0, result = 0;
                do
                {
                    b       = encoded[index++] - 63;
                    result |= (b & 0x1f) << shift;
                    shift  += 5;
                } while (b >= 0x20);
                int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
                lat += dlat;

                shift  = 0;
                result = 0;
                do
                {
                    b       = encoded[index++] - 63;
                    result |= (b & 0x1f) << shift;
                    shift  += 5;
                } while (b >= 0x20);
                int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
                lng += dlng;

                var p = new GeoLoc {
                    Lat = (((double)lat / 1E5)),
                    Lng = (((double)lng / 1E5))
                };
                poly.Add(p);
            }

            return(poly);
        }
Example #16
0
        public void cadastrarLoc(double latitude, double longitude, string TipoUsuario)
        {
            var data = new GeoLoc
            {
                latitude    = latitude,
                longitude   = longitude,
                TipoUsuario = TipoUsuario
            };

            try
            {
                IFirebaseConfig config = new FirebaseConfig
                {
                    AuthSecret = FirebaseSecret,
                    BasePath   = BasePath
                };
                _client = new FirebaseClient(config);

                _client.Push("/Localizacao_Usuarios", data);
            }
            catch (Exception erro)
            {
            }
        }
Example #17
0
 private double Distance(GeoLoc location1, GeoLoc location2)
 {
     return(CDistanceBetweenLocations.Calc(location1.Lat, location1.Lon, location2.Lat, location2.Lon));
 }
        /// <summary>
        /// Add points to the ride for video sync.
        /// videoTime = The number of seconds the video needs to travel the segment
        /// rideTime = The # of SECS at the end of the segment
        /// startTime = The # of SECS at the start of the segment
        /// endTime = the # of SECS at the end of the segment
        /// </summary>
        /// <returns></returns>
        public List <SAMPLE> AddPointsToNewRide(int videoTime, int startTime, int endTime, ref int thisOldRideCnt, ref int thisNewRideCnt, GoldenCheetahRide thisOldRide, ref GoldenCheetahRide thisNewRide)
        {
            testSegment.Clear();

#if (DEBUG)
            TextConnector tc       = new TextConnector();
            string        fullPath = tc.FullFilePath("debug" + startTime.ToString() + "-" + endTime.ToString() + ".csv", "debug");

            if (File.Exists(fullPath))
            {
                File.Delete(fullPath);
            }
#endif

            int pointsAdded = 0;
            int pointsMoved = 0;
            // Init vars
            int pointsToAdd = -1;
            int startCnt    = 0;
            int endCnt      = 0;
            int segmentTime = 0;
            // If this is not the first record we need to add a second to the video time
            videoTime++;
            segmentTime = endTime - startTime + 1;
            endCnt      = segmentTime - 1; // Last point is added manually
            pointsToAdd = videoTime - segmentTime;

            //Calculate distance and avg speed for the full segment
            GeoLoc     startpoint        = new GeoLoc(thisOldRide.RIDE.SAMPLES[startTime].LAT, thisOldRide.RIDE.SAMPLES[startTime].LON);
            GeoLoc     endpoint          = new GeoLoc(thisOldRide.RIDE.SAMPLES[endTime].LAT, thisOldRide.RIDE.SAMPLES[endTime].LON);
            GeoLocMath geoLocMath        = new GeoLocMath(startpoint, endpoint);
            double     distanceTravelled = geoLocMath.CalcDistanceBetweenGeoLocations();

            if (thisNewRide.RIDE.SAMPLES.Count() == 0)
            {
                // This is the first record.
                // Move initial point from old route to new route
                CopySampleToNewlist(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], ref thisNewRide);
                CopySampleToTestlist(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], ref testSegment);
#if (DEBUG)
                SaveLineToTxt(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], fullPath, thisOldRideCnt, thisNewRideCnt);
#endif
                thisNewRideCnt += 1;
                thisOldRideCnt++;
                startCnt++;
                pointsMoved++;
                endCnt--; // THIS
            }
            else
            {   //Check if point exists in new route before adding it
                if (Math.Abs(thisNewRide.RIDE.SAMPLES[thisNewRideCnt - 1].KM - thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].KM) > 0.01)
                {
                    // Move initial point from old route to new route
                    CopySampleToNewlist(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], ref thisNewRide);
                    CopySampleToTestlist(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], ref testSegment);
#if (DEBUG)
                    SaveLineToTxt(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], fullPath, thisOldRideCnt, thisNewRideCnt);
#endif
                    thisNewRideCnt += 1;
                    thisOldRideCnt++;
                    pointsMoved++;
                }
                else
                {
                    // First point is there already, move to the next one and decriment the number of points to move
                    startCnt++;
                    endCnt--;
                }
            }

            // If the last sample to add equals the segment length, add it right before the end
            //int lastSample = -1;
            //if ((pointsInterval * pointsToAdd) == endCnt) lastSample = endCnt - 1;

            if (pointsToAdd > (segmentTime / 2) && pointsToAdd < segmentTime)
            {
                //ADD every other point starting with (_segmentTime - _pointsToAdd) / 2
                MoreThanHalfPointsAddProcess(ref startCnt,
                                             ref endCnt,
                                             //ref pointsInterval,
                                             //ref lastSample,
                                             ref pointsToAdd,
                                             ref pointsAdded,
                                             ref thisOldRideCnt,
                                             ref thisNewRideCnt,
                                             ref pointsMoved,
                                             ref segmentTime,
                                             ref thisOldRide,
                                             ref thisNewRide,
                                             ref fullPath);
            }
            else if (pointsToAdd > (segmentTime / 2) && pointsToAdd > segmentTime)
            {
                Debug.WriteLine(" New Method here ");
                MorePointsThanWeHaveAddProcess(ref startCnt,
                                               ref endCnt,
                                               //ref pointsInterval,
                                               //ref lastSample,
                                               ref pointsToAdd,
                                               ref pointsAdded,
                                               ref thisOldRideCnt,
                                               ref thisNewRideCnt,
                                               ref segmentTime,
                                               ref thisOldRide,
                                               ref thisNewRide,
                                               ref fullPath);
            }
            else
            {
                //Calculate the number of points to add and the interval for adding them
                int pointsInterval = CalculateAddPointsInterval(pointsToAdd, segmentTime, endCnt, videoTime);
                LessThanHalfPointsAddProcess(ref startCnt,
                                             ref endCnt,
                                             ref pointsInterval,
                                             //ref lastSample,
                                             ref pointsToAdd,
                                             ref pointsAdded,
                                             ref thisOldRideCnt,
                                             ref thisNewRideCnt,
                                             ref pointsMoved,
                                             ref thisOldRide,
                                             ref thisNewRide,
                                             ref fullPath);
            }

            // Move last point from old route to new route
            CopySampleToNewlist(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], ref thisNewRide);
            CopySampleToTestlist(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], ref testSegment);
            SaveLineToTxt(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], fullPath, thisOldRideCnt, thisNewRideCnt);
            thisNewRideCnt += 1;
            thisOldRideCnt++;

            return(testSegment);
        }        // ***** addPointsToNewRide ENDS
        }        // ***** addPointsToNewRide ENDS

        /// <summary>
        /// Process to generate more points that currently available in the segment.
        /// </summary>
        /// <param name="startCnt"></param>
        /// <param name="endCnt"></param>
        /// <param name="pointsToAdd"></param>
        /// <param name="pointsAdded"></param>
        /// <param name="thisOldRideCnt"></param>
        /// <param name="thisNewRideCnt"></param>
        /// <param name="pointsMoved"></param>
        /// <param name="segmentTime"></param>
        /// <param name="thisOldRide"></param>
        /// <param name="thisNewRide"></param>
        /// <param name="fullPath"></param>
        private void MorePointsThanWeHaveAddProcess(ref int startCnt,
                                                    ref int endCnt,
                                                    //ref int pointsInterval,
                                                    //ref int lastSample,
                                                    ref int pointsToAdd,
                                                    ref int pointsAdded,
                                                    ref int thisOldRideCnt,
                                                    ref int thisNewRideCnt,
                                                    //ref int pointsMoved,
                                                    ref int segmentTime,
                                                    ref GoldenCheetahRide thisOldRide,
                                                    ref GoldenCheetahRide thisNewRide,
                                                    ref string fullPath)
        {
            //Save state
            int  savedStartCnt        = startCnt;
            int  savedthisOldRideCnt  = thisOldRideCnt;
            bool finishedMovingPoints = false;

            // Always start with the second point
            int startingPoint = 2;

            while (startCnt <= endCnt)
            {
                if (pointsAdded < pointsToAdd && startCnt >= startingPoint)
                {
                    // Add new sample
                    GeoLoc point1        = new GeoLoc(thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].LAT, thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].LON);
                    GeoLoc point2        = new GeoLoc(thisOldRide.RIDE.SAMPLES[thisOldRideCnt].LAT, thisOldRide.RIDE.SAMPLES[thisOldRideCnt].LON);
                    double newPointSlope = (thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].SLOPE + thisOldRide.RIDE.SAMPLES[thisOldRideCnt].SLOPE) / 2;
                    double newPointSpeed = (thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].KPH + thisOldRide.RIDE.SAMPLES[thisOldRideCnt].KPH) / 2;

                    GeoLocMath geoLocM1 = new GeoLocMath(point1, point2);
                    GeoLoc     newPoint = geoLocM1.CalcMidPoint();
                    geoLocM1.point1 = newPoint;
                    geoLocM1.point2 = point1;
                    double newdistanceTravelled = geoLocM1.CalcDistanceBetweenGeoLocations() + thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].KM;
                    // Create new sample and add data from above
                    SAMPLE newSample = new SAMPLE()
                    {
                        SECS  = 999, //insertPosition,
                        KM    = newdistanceTravelled,
                        KPH   = newPointSpeed,
                        ALT   = (thisOldRide.RIDE.SAMPLES[thisOldRideCnt].ALT + thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].ALT) / 2,
                        LAT   = newPoint.Latitude,
                        LON   = newPoint.Longitude,
                        SLOPE = newPointSlope
                    };
                    // Insert new point in ride
                    thisNewRide.RIDE.SAMPLES.Add(newSample);
                    testSegment.Add(newSample);
                    SaveLineToTxt(newSample, fullPath, -1, thisNewRideCnt);
                    thisNewRideCnt += 1;
                    //cnt = 1;
                    pointsAdded++;
                }

                if (!finishedMovingPoints)
                {
                    // Move sample to new ride
                    CopySampleToNewlist(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], ref thisNewRide);
                    CopySampleToTestlist(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], ref testSegment);
                    SaveLineToTxt(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], fullPath, thisOldRideCnt, thisNewRideCnt);
                    thisNewRideCnt += 1;
                    thisOldRideCnt++;
                    //cnt++;
                }

                startCnt++;

                if (pointsAdded < pointsToAdd && startCnt >= startingPoint && startCnt > endCnt)
                {
                    startCnt             = savedStartCnt;
                    thisOldRideCnt       = savedthisOldRideCnt;
                    finishedMovingPoints = true;
                }
            } // END of adding for loop

            // Need to check if all points needed were added.
            // If not, loop and add them

            //while (pointsAdded < pointsToAdd)
            //{

            //    AddNewPoint(
            //        ref thisOldRideCnt,
            //        ref thisNewRideCnt,
            //        ref pointsAdded,
            //        ref thisOldRide,
            //        ref thisNewRide,
            //        ref fullPath);

            //}

            //if (pointsAdded < pointsToAdd)
            //{
            //    throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().ToString() +
            //        $" -- Only added {pointsAdded} out of {pointsToAdd} ");
            //}
        }
Example #20
0
 public Vehicle(GeoLoc startingPoint, IList <IPassenger> passenger, List <Distance> distances)
 {
     _startingPoint = startingPoint;
     _passengers    = passenger;
     _distances     = distances;
 }
			"http://maps.googleapis.com/maps/api/directions/json?origin={0},{1}&destination={2},{3}&sensor={4}&mode={5}"; //&alternatives=true";

		public void GetRoutesAsync (Action<string> callback, GeoLoc src, GeoLoc dst, string mode = Driving)
		{
			DownloadStringAsync(r => callback(r), 
				String.Format(DirectionApiUrlFmt, src.Lat, src.Lng, dst.Lat, dst.Lng, "true", mode));
		}
		protected List<GeoLoc> DecodePoly(string encoded) {
			var poly = new List<GeoLoc>();
			int index = 0, len = encoded.Length;
			int lat = 0, lng = 0;

			while (index < len) {
				int b, shift = 0, result = 0;
				do {
					b = encoded[index++] - 63;
					result |= (b & 0x1f) << shift;
					shift += 5;
				} while (b >= 0x20);
				int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
				lat += dlat;

				shift = 0;
				result = 0;
				do {
					b = encoded[index++] - 63;
					result |= (b & 0x1f) << shift;
					shift += 5;
				} while (b >= 0x20);
				int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
				lng += dlng;

				var p = new GeoLoc{ Lat = (((double) lat / 1E5)),
					Lng = (((double) lng / 1E5))};
				poly.Add(p);
			}

			return poly;
		}
        // This method will add points to a  route segment if
        // the # of points to be added < half of the size of the segment
        private void LessThanHalfPointsAddProcess(ref int startCnt,
                                                  ref int endCnt,
                                                  ref int pointsInterval,
                                                  //ref int lastSample,
                                                  ref int pointsToAdd,
                                                  ref int pointsAdded,
                                                  ref int thisOldRideCnt,
                                                  ref int thisNewRideCnt,
                                                  ref int pointsMoved,
                                                  //ref double videoSpeed,
                                                  ref GoldenCheetahRide thisOldRide,
                                                  ref GoldenCheetahRide thisNewRide,
                                                  ref string fullPath)
        {
            //Loop and add points
            int cnt     = 1;
            int loopCnt = 0;

            while (startCnt <= endCnt)             // THIS
            {
                if (cnt == pointsInterval)         // || startCnt == lastSample)  // We only add points at pointsInterval
                {
                    if (pointsAdded < pointsToAdd) // Stop adding points because pointsInterval is converted to integer and not accurate
                    {
                        // Add new sample
                        GeoLoc point1        = new GeoLoc(thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].LAT, thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].LON);
                        GeoLoc point2        = new GeoLoc(thisOldRide.RIDE.SAMPLES[thisOldRideCnt].LAT, thisOldRide.RIDE.SAMPLES[thisOldRideCnt].LON);
                        double newPointSlope = (thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].SLOPE + thisOldRide.RIDE.SAMPLES[thisOldRideCnt].SLOPE) / 2;
                        double newPointSpeed = (thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].KPH + thisOldRide.RIDE.SAMPLES[thisOldRideCnt].KPH) / 2;

                        GeoLocMath geoLocM1 = new GeoLocMath(point1, point2);
                        GeoLoc     newPoint = geoLocM1.CalcMidPoint();
                        geoLocM1.point1 = newPoint;
                        geoLocM1.point2 = point1;
                        double newdistanceTravelled = geoLocM1.CalcDistanceBetweenGeoLocations() + thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].KM;

                        // Create new sample and add data from above
                        SAMPLE newSample = new SAMPLE()
                        {
                            SECS  = 999, //insertPosition,
                            KM    = newdistanceTravelled,
                            KPH   = newPointSpeed,
                            ALT   = (thisOldRide.RIDE.SAMPLES[thisOldRideCnt].ALT + thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].ALT) / 2,
                            LAT   = newPoint.Latitude,
                            LON   = newPoint.Longitude,
                            SLOPE = newPointSlope
                        };
                        // Insert new point in ride
                        thisNewRide.RIDE.SAMPLES.Add(newSample);
                        testSegment.Add(newSample);
                        SaveLineToTxt(newSample, fullPath, -1, thisNewRideCnt);
                        thisNewRideCnt += 1;
                        cnt             = 1;
                        pointsAdded++;
                    }
                }
                // Move sample to new ride
                CopySampleToNewlist(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], ref thisNewRide);
                CopySampleToTestlist(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], ref testSegment);
                SaveLineToTxt(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], fullPath, thisOldRideCnt, thisNewRideCnt);
                thisNewRideCnt += 1;
                thisOldRideCnt++;
                cnt++;
                pointsMoved++;
                loopCnt++;
                startCnt++;
            } // END of addong for loop
        }
Example #24
0
 public static LatLng GetLatLng(GeoLoc loc)
 {
     return(new LatLng(loc.Lat, loc.Lng));
 }
Example #25
0
        public static (IList <IList <IPassenger> > vehicles, double totalDistance) CalculateMultipleCarsPathForSmallestDistanceTraveled(GeoLoc startingPoint, List <IPassenger> allPassengers, List <Distance> allDistances)
        {
            IEnumerable <IList <IList <IPassenger> > > partitions = allPassengers.Partitions();

            int partitionCount = partitions.Count();

            var partitionIndexAndItsDistance = new Tuple <int, double> [partitionCount];

            var vehiclesWithDistances = new HashSet <Vehicle>();

            for (int i = 0; i < partitionCount; i++)
            //Parallel.For(0, partitions.Count(), i =>
            {
                IList <IList <IPassenger> > groups = partitions.ElementAt(i);

                double totalDistance = 0;

                foreach (var passengers in groups)
                {
                    var vehicle = new Vehicle(startingPoint, passengers, allDistances);

                    Vehicle withDistance;
                    bool    isFound = vehiclesWithDistances.TryGetValue(vehicle, out withDistance);

                    if (isFound)
                    {
                        totalDistance += withDistance.GetDistance();
                    }
                    else
                    {
                        totalDistance += vehicle.GetDistance();
                        vehiclesWithDistances.Add(vehicle);
                    }
                }

                partitionIndexAndItsDistance[i] = new Tuple <int, double>(i, totalDistance);

                Console.SetCursorPosition(0, 1);
                Console.Write(partitionCount + " - " + i);
            }
            ;

            var winner = partitionIndexAndItsDistance.OrderBy(i => i.Item2).First();

            return(vehicles : partitions.ElementAt(winner.Item1), totalDistance : winner.Item2);
        }
		public MapPointsActivityBase(int layoutId, int mapPointTextId, GeoLoc mapCentre)
		{
			_layoutId = layoutId;
			_wRoutesMapperImpl = new WalkingRoutesMapperImpl (this) { MapCentre = mapCentre, MapPointTextId = mapPointTextId };
		}
		protected abstract void MoveCamera (GeoLoc mapCentre);
			protected override void MoveCamera (GeoLoc mapCenter)
			{
				var map = _mapFragment.Map;
				var cameraUpdate = CameraUpdateFactory.NewLatLngZoom(Utils.GetLatLng(mapCenter), 15);
				map.MoveCamera(cameraUpdate);
			}
Example #29
0
 private Passenger(int id, string name, GeoLoc destination)
 {
     ID          = id;
     Name        = name;
     Destination = destination;
 }
Example #30
0
 public static CLLocationCoordinate2D GetCLLoc(GeoLoc loc)
 {
     return(new CLLocationCoordinate2D(loc.Lat, loc.Lng));
 }
Example #31
0
 public MapPointsControllerBase(IntPtr handle, GeoLoc mapCenter) : base(handle)
 {
 }
Example #32
0
        public static double GeoDistance(GeoLoc pt1, GeoLoc pt2)
        {
            double MetrePerDegLng = MetrePerDegLat * Math.Abs(Math.Cos(pt1.Lat));

            return(MetrePerDegLat * Math.Abs(pt1.Lat - pt2.Lat) + MetrePerDegLng * Math.Abs(pt1.Lng - pt2.Lng));
        }
Example #33
0
        internal GeoLoc GetMyGeoLocation()
        {
            GeoLoc _geoLoc = new GeoLoc();

            try
            {
                //create a request to geoiptool.com
                var request = WebRequest.Create(new Uri("http://geoiptool.com/data.php")) as HttpWebRequest;


                if (request != null)
                {
                    //set the request user agent
                    request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727)";

                    //get the response
                    using (var webResponse = (request.GetResponse() as HttpWebResponse))
                        if (webResponse != null)
                        {
                            using (var reader = new StreamReader(webResponse.GetResponseStream()))
                            {
                                //get the XML document
                                var doc = new XmlDocument();
                                doc.Load(reader);

                                //now we parse the XML document
                                var nodes = doc.GetElementsByTagName("marker");

                                // Guard.AssertCondition(nodes.Count > 0, "nodes", new object());
                                //make sure we have nodes before looping
                                //if (nodes.Count > 0)
                                //{
                                //grab the first response
                                var marker = nodes[0] as XmlElement;

                                //  Guard.AssertNotNull(marker, "marker");

                                //get the data and return it
                                _geoLoc.City      = marker.GetAttribute("city");
                                _geoLoc.Country   = marker.GetAttribute("country");
                                _geoLoc.Code      = marker.GetAttribute("code");
                                _geoLoc.Host      = marker.GetAttribute("host");
                                _geoLoc.Ip        = marker.GetAttribute("ip");
                                _geoLoc.Latitude  = marker.GetAttribute("lat");
                                _geoLoc.Lognitude = marker.GetAttribute("lng");
                                _geoLoc.State     = GetMyState(_geoLoc.Latitude, _geoLoc.Lognitude);

                                return(_geoLoc);
                                //}
                            }
                        }
                }

                // this code would only be reached if something went wrong
                // no "marker" node perhaps?
                return(_geoLoc);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
            "http://maps.googleapis.com/maps/api/directions/json?origin={0},{1}&destination={2},{3}&sensor={4}&mode={5}";             //&alternatives=true";

        public void GetRoutesAsync(Action <string> callback, GeoLoc src, GeoLoc dst, string mode = Driving)
        {
            DownloadStringAsync(r => callback(r),
                                String.Format(DirectionApiUrlFmt, src.Lat, src.Lng, dst.Lat, dst.Lng, "true", mode));
        }
Example #35
0
		public static LatLng GetLatLng(GeoLoc loc)
		{
			return new LatLng (loc.Lat, loc.Lng);
		}
Example #36
0
 protected abstract void MoveCamera(GeoLoc mapCentre);
Example #37
0
		public static double GeoDistance (GeoLoc pt1, GeoLoc pt2)
		{
			double MetrePerDegLng = MetrePerDegLat * Math.Abs(Math.Cos (pt1.Lat));
			return MetrePerDegLat *  Math.Abs(pt1.Lat - pt2.Lat) + MetrePerDegLng * Math.Abs(pt1.Lng - pt2.Lng);
		}