Example #1
0
        //API call to google->gets a JSON packet which is deciphered
        void mapAPICall(PartnerVehicle partnervehicle)
        {
            string placeofvehicle = partnervehicle.getlocstring();

            try
            {
                string url = "";
                if (truckbool == false)
                {
                    //route from trucks place to own finishers location
                    url = "http://maps.googleapis.com/maps/api/directions/json?origin=" + placeofvehicle + "&destination=" + ownlocstring + "&sensor=false";
                }
                else
                {
                    //route from own trucks place to finishers location
                    url = "http://maps.googleapis.com/maps/api/directions/json?origin=" + ownlocstring + "&destination=" + placeofvehicle + "&sensor=false";
                }

                string requesturl = url; string content = fileGetJSON(requesturl);;
                _Jobj = JObject.Parse(content);
                Log.Debug("apicall", content.ToString());
            }
            catch { }

            //start durationthread
            Thread durationThread = new Thread(() => getDuration(partnervehicle));

            durationThread.Start();
        }
Example #2
0
        //draw route from polylines in json object
        void drawRoute(PartnerVehicle partnervehicle)
        {
            Log.Debug("http", "drawroutestart");

            PolylineOptions temppoly = new PolylineOptions();

            if (truckbool == false)
            {
                //variable colours for different trucks

                //green for nearest truck
                if (partnervehicle.getNearest() == true)
                {
                    Log.Debug("drawroute", "nearest");
                    temppoly.InvokeColor(0x6600cc00);
                }

                //other colors for normal route
                else if (partnervehicle.getcolor() == "blue")
                {
                    temppoly.InvokeColor(0x66000099);
                }
                else if (partnervehicle.getcolor() == "red")
                {
                    temppoly.InvokeColor(0x66ff0000);
                }
                else if (partnervehicle.getcolor() == "black")
                {
                    temppoly.InvokeColor(0x66000000);
                }
                else if (partnervehicle.getcolor() == "purple")
                {
                    temppoly.InvokeColor(0x669933ff);
                }
                else
                {
                    //blue
                    Log.Debug("drawroute", "else");
                    temppoly.InvokeColor(0x66000099);
                }
            }

            else
            {
                //route from truck to finisher in blue
                temppoly.InvokeColor(0x66000099);
            }

            //setwidth
            temppoly.InvokeWidth(13);

            //get polypoints from json object
            try
            {
                string polyPoints;
                polyPoints = (string)_Jobj.SelectToken("routes[0].overview_polyline.points");
                List <LatLng> drawCoordinates;
                drawCoordinates = DecodePolylinePoints(polyPoints);
                foreach (var position in drawCoordinates)
                {
                    temppoly.Add(new LatLng(position.Latitude, position.Longitude));
                }
                partnervehicle.setPolylineOptions(temppoly);
            }
            catch
            {}

            //draw route in main UI thread
            RunOnUiThread(() => updateUI());
        }
Example #3
0
        public void getDuration(PartnerVehicle partnervehicle)
        {
            //get duration from JSON
            int dur = getDistanceTo();
            int min = int.MaxValue;

            //set duration of partnervehicle
            partnervehicle.setDur(dur);

            Log.Debug("durationmin", min.ToString());
            Log.Debug("durationdur", dur.ToString());

            //set nearest to false for every truck
            foreach (PartnerVehicle aPartnerVehicle in partnerlist)
            {
                aPartnerVehicle.setNearest(false);
            }

            //temp value so change of nearest truck can easily be found
            PartnerVehicle test = partnerlist.First();

            //sort on duration -> nearest truck first in list
            partnerlist.Sort((x, y) => x.getDur().CompareTo(y.getDur()));
            partnerlist.First().setNearest(true);

            //check if new truck is newest truck, if yes update previous nearest truck so its route is not green
            if (test != partnerlist.First())
            {
                Thread mapAPICall3 = new Thread(() => mapAPICall(test));
                mapAPICall3.Start();
            }

            //seconds to TimeSpan
            TimeSpan t = TimeSpan.FromSeconds(partnerlist.First().getDur());

            //time to hours/minutes/seconds
            string time;

            partnerduration = partnerlist.First().getDur();
            if (partnerduration <= 60)
            {
                time = t.ToString(@"ss") + "s";
            }
            else if (partnerduration <= 3600)
            {
                time = t.ToString(@"mm\mss") + "s";
            }
            else
            {
                time = t.ToString(@"hh\hmm\mss") + "s";
            }

            if (truckbool == false)
            {
                durationString = "ETA of nearest truck: " + time;
            }
            else
            {
                durationString = "ETA at finisher: " + time;
            }

            TextView durationtextfield = FindViewById <TextView>(Resource.Id.durationText);

            //update textfield in main UI thread
            RunOnUiThread(() => durationtextfield.Text = durationString);

            //draw the route
            Thread drawRouteThread = new Thread(() => drawRoute(partnervehicle));

            drawRouteThread.Start();

            //update notification so duration stays updated
            UpdateNotification();
        }