public static ManualAnomaly MapToAnomaly(this AnomalyModel anomalyModel)
        {
            double?snappedLatitude  = null;
            double?snappedLongitude = null;

            using (var client = new HttpClient())
            {
                string path = String.Format("https://roads.googleapis.com/v1/snapToRoads?path={0}&key={1}", anomalyModel.Latitude + "," + anomalyModel.Longitude, Constants.GoogleMapsRoadsAPIKey);
                HttpResponseMessage response = client.GetAsync(path).Result;
                if (response.IsSuccessStatusCode)
                {
                    SnappedPath snappedPath = response.Content.ReadAsAsync <SnappedPath>().Result;

                    if (snappedPath != null && snappedPath.snappedPoints != null && snappedPath.snappedPoints.Count() > 0)
                    {
                        snappedLatitude  = snappedPath.snappedPoints.ElementAt(0).location.Latitude;
                        snappedLongitude = snappedPath.snappedPoints.ElementAt(0).location.Longitude;
                    }
                }
            }

            return(new ManualAnomaly()
            {
                Latitude = anomalyModel.Latitude,
                Longitude = anomalyModel.Longitude,
                SnappedLatitude = snappedLatitude,
                SnappedLongitude = snappedLongitude,
                Type = anomalyModel.Type
            });
        }
Beispiel #2
0
        public IHttpActionResult Create(AnomalyModel model)
        {
            int id = service.Create(model.MapToAnomaly());

            if (id > 0)
            {
                return(Ok(new GeneralModel()
                {
                    Success = 1, Message = "Saved successfully"
                }));
            }
            else
            {
                return(Ok(new GeneralModel()
                {
                    Success = 0, Message = "Error Saving Anomaly"
                }));
            }
        }