Inheritance: ILocationString
        /// <summary>
        /// Execute the Command: collect the fields of the Model from the multi-converter in the View and set the values in the ViewModel
        /// </summary>
        /// <param name="parameter">parameters that were collected form the View usin</param>
        public async void Execute(object parameter)
        {
            var    values = (object[])parameter;
            Report report = new Report();

            report.name         = values[0].ToString();
            report.timeOfReport = DateTime.Parse(values[1].ToString());
            string address = values[2].ToString();

            try
            {
                GeocodingRequest geocodeRequest = new GeocodingRequest();
                geocodeRequest.Address = address;
                geocodeRequest.ApiKey  = googleMapsKey;
                GeocodingResponse geocode = await GoogleMaps.Geocode.QueryAsync(geocodeRequest);

                if (geocode.Status == Status.OK)
                {
                    IEnumerator <Result> iter = geocode.Results.GetEnumerator();
                    iter.MoveNext();
                    GM.Location tempLocation = iter.Current.Geometry.Location;
                    latitude  = tempLocation.Latitude;
                    longitude = tempLocation.Longitude;
                }
            }
            catch (Exception exception) { }

            report.Latitude          = latitude;  //coord.Latitude;
            report.Longitude         = longitude; //  coord.Longitude;
            report.numOfBombs        = int.Parse(values[3].ToString());
            report.cityName          = values[4].ToString();
            CurrentVM.incomingReport = report;
        }
コード例 #2
0
ファイル: Trip.cs プロジェクト: gotcreme/HotCar
        public void CreateDirectionsResponse()
        {
            Location[] locations = new Location[this.RouteLocations.Count];
            for (int a = 0; a < locations.Length; a++)
            {
                locations[a] = new Location(this.RouteLocations[a].Latitude, this.RouteLocations[a].Longitude);
            }

            String[] wayPoints = new String[locations.Length - 2];
            for (int a = 1; a < locations.Length - 1; a++)
            {
                wayPoints[a - 1] = locations[a].LocationString;
            }

            DirectionsRequest directionsRequest = new DirectionsRequest()
            {
                Origin = locations[0].LocationString,
                Destination = locations[locations.Length - 1].LocationString,
                Waypoints = wayPoints,
                TravelMode = TravelMode.Driving,
                ApiKey = ConfigurationManager.AppSettings["GoogleMapsAPIKey"]
            };

            this.DirectionsResponse = GoogleMapsApi.GoogleMaps.Directions.Query(directionsRequest);
        }
コード例 #3
0
ファイル: Trip.cs プロジェクト: gotcreme/HotCar
        private bool IsLocationOnEdge(Location[] locations, String from, string to, double tolerance)
        {
            GeocodingRequest startRequest = new GeocodingRequest()
            {
                Address = from,
                ApiKey = ConfigurationManager.AppSettings["GoogleMapsAPIKey"]
            };

            GeocodingRequest endRequest = new GeocodingRequest()
            {
                Address = to,
                ApiKey = ConfigurationManager.AppSettings["GoogleMapsAPIKey"]

            };

            GeocodingResponse startResponse = GoogleMapsApi.GoogleMaps.Geocode.Query(startRequest);
            GeocodingResponse endResponse = GoogleMapsApi.GoogleMaps.Geocode.Query(endRequest);

            Location startLocation = startResponse.Results.ElementAt(0).Geometry.Location;
            Location endLocation = endResponse.Results.ElementAt(0).Geometry.Location;

            bool startIsOnEdge = false;
            bool endIsOnEdge = false;

            for (int a = 0; a < locations.Length; a++)
            {
                if (!startIsOnEdge && this.GetStraightDistance(locations[a], startLocation) <= tolerance)
                {
                    startIsOnEdge = true;
                }

                if (!endIsOnEdge && this.GetStraightDistance(locations[a], endLocation) <= tolerance)
                {
                    endIsOnEdge = true;
                }

                if (startIsOnEdge && endIsOnEdge)
                {
                    break;
                }
            }

            if (startIsOnEdge && endIsOnEdge)
            {
                return true;
            }

            return false;
        }
コード例 #4
0
ファイル: Trip.cs プロジェクト: gotcreme/HotCar
        private double GetStraightDistance(Location location, Location location2)
        {
            double R = 6371000;
            double dLat = this.ToRad(location2.Latitude - location.Latitude);
            double dLon = this.ToRad(location2.Longitude - location.Longitude);

            double dLat1 = this.ToRad(location.Latitude);
            double dLat2 = this.ToRad(location2.Latitude);

            var a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) +
                    Math.Cos(dLat1) * Math.Cos(dLat1) *
                    Math.Sin(dLon / 2) * Math.Sin(dLon / 2);
            var c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
            double distance = R * c;
            return distance;
        }
コード例 #5
0
ファイル: Trip.cs プロジェクト: gotcreme/HotCar
        private Location[] DecodePolyline(String encodedPoints)
        {
            if (string.IsNullOrEmpty(encodedPoints))
            {
                return null;
            }

            List<Location> locations = new List<Location>();
            char[] polyLineChars = encodedPoints.ToCharArray();

            int index = 0;
            int currentLat = 0;
            int currentLng = 0;
            int next5bits;

            while (index < polyLineChars.Length)
            {
                int sum = 0;
                int shifter = 0;

                do
                {
                    next5bits = (int)polyLineChars[index++] - 63;
                    sum |= (next5bits & 31) << shifter;
                    shifter += 5;
                } while (next5bits >= 32 && index < polyLineChars.Length);

                if (index >= polyLineChars.Length)
                {
                    break;
                }

                currentLat += (sum & 1) == 1 ? ~(sum >> 1) : (sum >> 1);

                sum = 0;
                shifter = 0;
                do
                {
                    next5bits = (int)polyLineChars[index++] - 63;
                    sum |= (next5bits & 31) << shifter;
                    shifter += 5;
                } while (next5bits >= 32 && index < polyLineChars.Length);

                if (index >= polyLineChars.Length && next5bits >= 32)
                {
                    break;
                }

                currentLng += (sum & 1) == 1 ? ~(sum >> 1) : (sum >> 1);
                Location p = new Location(0, 0);
                p.Latitude = Convert.ToDouble(currentLat) / 100000.0;
                p.Longitude = Convert.ToDouble(currentLng) / 100000.0;
                locations.Add(p);
            }

            return locations.ToArray();
        }
コード例 #6
0
 public void WhenNearZeroLongitude_ExpectCorrectToString()
 {
     // Longitude of 0.000009 is converted to 9E-06 using Invariant ToString, but we need 0.000009
     var location = new Location(57.231d, 0.000009d);
     Assert.AreEqual("57.231,0.000009", location.ToString());
 }