public ActionResult ValidateAdress([FromBody] Location location)
        {
            if (location == null)
            {
                return(BadRequest(new Location()));
            }
            else
            {
                Location loc = null;
                Task.WaitAll(Task.Run(async() => loc = await GeoCoding.GetLocationByAdress(location.HouseNumber, location.StreetName, location.CityName)));

                if (loc == null)
                {
                    return(StatusCode(406)); //Not Acceptable
                }
                else if (location.CountryName == loc.CountryName &&
                         location.HouseNumber == loc.HouseNumber)
                {
                    //loc is not null
                    if (location.CityName == loc.CityName ||
                        loc.CityName.ToString().Contains(location.CityName.ToString()) ||
                        location.CityName.ToString().Contains(loc.CityName.ToString()))
                    {
                        return(Ok(new AddPartyJSON(_dbContext, User).AddValidStateToLocation(loc, true)));
                    }

                    return(StatusCode(406, new AddPartyJSON(_dbContext, User).AddValidStateToLocation(loc, false)));
                }
                else
                {
                    return(StatusCode(406, new AddPartyJSON(_dbContext, User).AddValidStateToLocation(loc, false)));
                }
            }
        }
示例#2
0
        private void geocodingTest()
        {
            DbUtilities d             = new DbUtilities();
            string      geo_json_data = d.getAllDataFromJsonFile(@"C:\Users\hkylidis\Desktop\rev_geocoding_el.json");

            GeoCoding a = d.stringToGenericObject <GeoCoding>(geo_json_data);

            if (a.status.ToUpper() == "OK")
            {
                string areaLevel1 = a.results.Where(i => i.types.Contains("administrative_area_level_1")).FirstOrDefault().address_components.Where(i => i.types.Contains("administrative_area_level_1")).FirstOrDefault().long_name;
                string areaLevel2 = a.results.Where(i => i.types.Contains("administrative_area_level_2")).FirstOrDefault().address_components.Where(i => i.types.Contains("administrative_area_level_2")).FirstOrDefault().long_name;
                string areaLevel3 = a.results.Where(i => i.types.Contains("administrative_area_level_3")).FirstOrDefault().address_components.Where(i => i.types.Contains("administrative_area_level_3")).FirstOrDefault().long_name;
                string areaLevel4 = a.results.Where(i => i.types.Contains("administrative_area_level_4")).FirstOrDefault().address_components.Where(i => i.types.Contains("administrative_area_level_4")).FirstOrDefault().long_name;
            }
        }
示例#3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // This commented line is enough to make it work!!!
            // GMap1.addGeoCode(new GeoCoding());

            GMap1.GZoom = 9;
            GMap1.Add(new GControl(GControl.preBuilt.LargeMapControl));

            GeoCoding geoCoding = new GeoCoding();

            geoCoding.show         = GeoCoding.ShowEnum.infowindow;
            geoCoding.openedOnLoad = true;
            geoCoding.errorText    = "No tá";
            geoCoding.buttonText   = "Buscar";
            geoCoding.infoText     = "Buscar GeoCode";

            GMap1.Add(geoCoding);
        }
示例#4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // This commented line is enough to make it work!!!
            // GMap1.addGeoCode(new GeoCoding());

            GMap1.GZoom = 9;
            GMap1.Add(new GControl(GControl.preBuilt.LargeMapControl));

            GeoCoding geoCoding = new GeoCoding();

            geoCoding.show = GeoCoding.ShowEnum.infowindow;
            geoCoding.openedOnLoad = true;
            geoCoding.errorText = "No tá";
            geoCoding.buttonText = "Buscar";
            geoCoding.infoText = "Buscar GeoCode";

            GMap1.Add(geoCoding);
        }
示例#5
0
    public static void Main()
    {
        Console.WriteLine("Weather Forcast: Brought to you by DarkSky! Enter your Zip Code to Get Started: ");

        string zip = Console.ReadLine();

        var url = String.Format("https://maps.googleapis.com/maps/api/geocode/json?address=" + zip);

        var net = new WebClient();

        string reply = net.DownloadString(url);

        Console.WriteLine(reply);
        Console.WriteLine("Your location coordinates: ");
        //Console.ReadLine();

        GeoCoding m = JsonConvert.DeserializeObject <GeoCoding>(reply);

        Console.WriteLine("{0},{1}", m.results[0].geometry.location.lat, m.results[0].geometry.location.lng);

        Console.WriteLine("Now Press Enter for the Weather!");
        Console.ReadLine();

        var url2 = String.Format("https://api.darksky.net/forecast/99365e9edb960a6f4591753f0e054c8e/" + m.results[0].geometry.location.lat + "," + m.results[0].geometry.location.lng);

        var net2 = new WebClient();

        string reply2 = net2.DownloadString(url2);

        Console.WriteLine(reply2);

        RootObject r = JsonConvert.DeserializeObject <RootObject>(reply2);

        Console.WriteLine();
        Console.WriteLine();
        Console.WriteLine();
        Console.WriteLine("...Whoops, that's not right, is it? Let's try again. Hit Enter Again!");

        Console.ReadLine();
    }
        public ActionResult GetWithUserLocation(double lat, double lon, float radius)
        {
            try
            {
                if (radius < 0 || radius > 200)
                {
                    //Radius is out of range
                    return(BadRequest("Radius is out of range. Please pass a value between 0 and 200."));
                }
                else
                {
                    //Test
                    List <JObject> jsonList = new List <JObject>();

                    var partys = _dbContext.PartyItems
                                 .Where(p => p.PartyDate >= DateTime.Today)
                                 .Include(p => p.Location)
                                 .Include(p => p.Host).ToList();

                    if (partys == null)
                    {
                        return(NotFound("There are no partys in the future."));
                    }
                    else
                    {
                        //NOTE: Outcommented code is to get the nearest results. At the moment not used.

                        //Initialize list do save the party Id and the distance to the user
                        //List<Tuple<Guid, double?>> partyDistanceList = new List<Tuple<Guid, double?>>();
                        foreach (Party singleParty in partys)
                        {
                            double?distance = GeoCoding.GetDistance(lat, lon, singleParty.Location.Latitude, singleParty.Location.Longitude);

                            if (distance != null)
                            {
                                if (distance <= radius)
                                {
                                    //Save party Id and distance
                                    //partyDistanceList.Add(new Tuple<Guid, double?> ( singleParty.PartyId, distance ));

                                    //Party is near to the user location
                                    jsonList.Add(new AddPartyJSON(_dbContext, User).AddCustomJson(singleParty));
                                }
                            }
                        }

                        //if(partyDistanceList.Count <= 0)
                        //{
                        //    return BadRequest("No party in your nearness.");
                        //}
                        //else
                        //{
                        //    //Sort list by distance and take the first "maxResults"-entries
                        //    IEnumerable<Tuple<Guid, double?>> sortedList = partyDistanceList.OrderBy(l => l.Item2).ToList().Take(maxResults);
                        //    foreach(var singleEntry in sortedList)
                        //    {
                        //        var party = partys.FirstOrDefault(p => p.PartyId == singleEntry.Item1);
                        //        if(party != null)
                        //        {
                        //            //Party is near to the user location
                        //            jsonList.Add(AddCustomJson(party));
                        //        }
                        //    }
                        //}
                        return(Ok(jsonList));
                    }
                }
            }
            catch (Exception)
            {
                return(BadRequest("Paramter in URL: ...?lat=49...&lon=9....&radius=2..."));
            }
        }