Beispiel #1
0
        //Gebaseerd op adres, stad en postcode returned deze methode een SimpleWaypoint van die plek in longtitude en latitude
        public async Task <SimpleWaypoint> AdressToCoor(string street, int houseNumber, string city, string postalCode)
        {
            GeocodeRequest geocode = new GeocodeRequest();
            SimpleAddress  address = new SimpleAddress();

            address.AddressLine = street + houseNumber;
            address.Locality    = city;
            address.PostalCode  = postalCode;

            geocode.Address     = address;
            geocode.BingMapsKey = bingMapKey;

            var response = await geocode.Execute();

            if (response != null &&
                response.ResourceSets != null &&
                response.ResourceSets.Length > 0 &&
                response.ResourceSets[0].Resources != null &&
                response.ResourceSets[0].Resources.Length > 0)
            {
                Location       result   = response.ResourceSets[0].Resources[0] as BingMapsRESTToolkit.Location;
                SimpleWaypoint waypoint = new SimpleWaypoint(result.GeocodePoints[1].Coordinates[0], result.GeocodePoints[1].Coordinates[1]);
                return(waypoint);
            }

            return(null);
        }
Beispiel #2
0
        private static Point GetLocation(string address)
        {
            var request = new GeocodeRequest()
            {
                Query               = address,
                IncludeIso2         = true,
                IncludeNeighborhood = true,
                MaxResults          = 5,
                BingMapsKey         = Environment.GetEnvironmentVariable("BingMapsKey")
            };

            var response = request.Execute().Result;

            if (response != null &&
                response.ResourceSets != null &&
                response.ResourceSets.Length > 0 &&
                response.ResourceSets[0].Resources != null &&
                response.ResourceSets[0].Resources.Length > 0)
            {
                var result = response.ResourceSets[0].Resources[0] as Location;

                return(new Point(result.Point.Coordinates[0], result.Point.Coordinates[1]));
            }

            return(new Point(0, 0));
        }
Beispiel #3
0
        // UPDATED (old method left commented out below updated method)
        // convert Bing address to lat/lon
        public MyWaypoint Geocode(string address)
        {
            //MessageBox.Show($"Geocode method called for !! {address} "); // FOR DEBUGGING PURPOSES
            // create the Geocode request
            GeocodeRequest locationRequest = new GeocodeRequest
            {
                BingMapsKey         = m_bingMapKey,
                MaxResults          = 1,
                IncludeNeighborhood = true,
                IncludeIso2         = true,
                Query = address
            };

            //MessageBox.Show("About to execute location request!");// FOR DEBUGGING PURPOSES
            // execute the response
            // this call can also use await, but then method would have to be made async
            Response geocodeResponse = locationRequest.Execute().Result;
            //MessageBox.Show("Executed location Request!");// FOR DEBUGGING PURPOSES

            // set lat/lon/altitude of waypoint and return waypoint
            MyWaypoint returnPoint = new MyWaypoint();

            if (geocodeResponse.ResourceSets.Length > 0)
            {
                var result = geocodeResponse.ResourceSets[0].Resources[0] as BingMapsRESTToolkit.Location;
                returnPoint.Latitude  = result.Point.Coordinates[0];
                returnPoint.Longitude = result.Point.Coordinates[1];
                returnPoint.Altitude  = 0.0;
            }
            //MessageBox.Show("Geocode method done!");// FOR DEBUGGING PURPOSES
            return(returnPoint);
        }
        public ValidatedAddress ValidateAddress(GeoQuery query)
        {
            var request = new GeocodeRequest
            {
                BingMapsKey = Startup.BingKey,
                Query       = query.ToString()
            };

            var result = request.Execute().Result;

            if (result.ResourceSets.Length > 0)
            {
                var location = (Location)result.ResourceSets[0].Resources[0];
                if (location.Address.Locality.IsNullOrWhiteSpace() || location.Address.AddressLine.IsNullOrWhiteSpace())
                {
                    return(new ValidatedAddress {
                        ConfidenceLevel = ConfidenceLevel.None
                    });
                }
                else
                {
                    return(_mapper.Map <ValidatedAddress>(location));
                }
            }

            return(new ValidatedAddress {
                ConfidenceLevel = ConfidenceLevel.None
            });
        }
Beispiel #5
0
        private static async Task GeocodeAddress(TDayAddress addr, ConcurrentBag <TDayAddress> goodAddr, ConcurrentBag <TDayAddress> badAddr, MsgOut msgOut)
        {
            var bingKey = "Aq03fYCDuaMZk0OxpH97nxHInqIsJDzab90p3twCHCk8CvlRoKjB4Xs5Msbgsvq6";

            // ServiceManager.Proxy = new WebProxy("http://proxy.research.ge.com:80/");

            var request = new GeocodeRequest()
            {
                Query               = addr.ToAddress(),
                IncludeIso2         = true,
                IncludeNeighborhood = true,
                MaxResults          = 25,
                BingMapsKey         = bingKey
            };
            //Process the request by using the ServiceManager.
            var response = await request.Execute();

            if (response != null &&
                response.ResourceSets != null &&
                response.ResourceSets.Length > 0 &&
                response.ResourceSets[0].Resources != null &&
                response.ResourceSets[0].Resources.Length > 0)
            {
                Location foundAddr = null;

                foreach (var res in response.ResourceSets[0].Resources)
                {
                    if (((Location)res).Address.AdminDistrict == "NY" && ((Location)res).Address.PostalCode != null && ((Location)res).Address.PostalCode.StartsWith("12"))
                    {
                        foundAddr = (Location)res;
                        break;
                    }
                }
                //var result = response.ResourceSets[0].Resources[0] as Location;

                if (foundAddr != null && foundAddr.MatchCodes[0].ToString() == "Good")
                {
                    addr.Address1 = foundAddr.Address.AddressLine;
                    addr.City     = foundAddr.Address.Locality;
                    addr.State    = foundAddr.Address.AdminDistrict;
                    addr.Zip      = foundAddr.Address.PostalCode;
                    var coords = foundAddr.Point.Coordinates;
                    if (coords != null && coords.Length == 2)
                    {
                        addr.Lat = (float)coords[0];
                        addr.Lon = (float)coords[1];
                    }
                    goodAddr.Add(addr);
                }
                else
                {
                    badAddr.Add(addr);
                }
                //msgOut($"Geocode: {addr} => Results - Code: {result.MatchCodes[0]}\r");
            }
        }
Beispiel #6
0
        public async Task <Address> GetFullAdress(string address)
        {
            GeocodeRequest req = new GeocodeRequest()
            {
                BingMapsKey = _bingApiKey,
                Query       = "NL " + address
            };

            Response response = await req.Execute();

            Location location = response.ResourceSets[0].Resources[0] as Location;

            return(location.Address);
        }
Beispiel #7
0
         private async void GetFind()
         {    
             var request = new GeocodeRequest()
             {
                 Query = "Via trento 1, Sondrio",
                 IncludeIso2 = true,
                 IncludeNeighborhood = true,
                 MaxResults = 25,
                 BingMapsKey = BingKey
             };
 
 
             //Process the request by using the ServiceManager.
             var response = await request.Execute();
 
             if (response != null &&
                 response.ResourceSets != null &&
                 response.ResourceSets.Length > 0 &&
                 response.ResourceSets[0].Resources != null &&
                 response.ResourceSets[0].Resources.Length > 0)
             {
                 var result = response.ResourceSets[0].Resources[0] as Location;
 
                 var myAddr = result.Address.AddressLine;
                 var CAP = result.Address.PostalCode;
                 var City = result.Address.Locality;
                 var Province = result.Address.AdminDistrict2;
                 var Region = result.Address.AdminDistrict;
                 var Stato = result.Address.CountryRegion;
 
                 var coords = result.Point.Coordinates;
                 if (coords != null && coords.Length == 2)
                 {
                     var lat = coords[0];
                     var lng = coords[1];
 
                     string Latitude = String.Format("{0:00.000000}", lat);
                     string Longitude = String.Format("{0:000.000000}", lng);
 
                     txtResult.Text = "Indirizzo: " + myAddr +
                         Environment.NewLine + "CAP: " + CAP +
                         Environment.NewLine + "Città: " + City +
                         Environment.NewLine + "Provincia: " + Province +
                         Environment.NewLine + "Regione: " + Region +
                         Environment.NewLine + "Stato: " + Stato + 
                         Environment.NewLine + $"Coordinate - Lat: {Latitude} / Long: {Longitude}"
                         ;
                 }
             }
         } 
Beispiel #8
0
        public async Task <DailyChallengeEntry> GetLocationDetails(string locationQueryText, ILogger logger)
        {
            try
            {
                //Create a request.
                var request = new GeocodeRequest()
                {
                    Query               = locationQueryText,
                    IncludeIso2         = true,
                    IncludeNeighborhood = true,
                    MaxResults          = 25,
                    BingMapsKey         = BingMapsKey
                };

                //Process the request by using the ServiceManager.
                var response = await request.Execute();

                if (response != null &&
                    response.ResourceSets != null &&
                    response.ResourceSets.Length > 0 &&
                    response.ResourceSets[0].Resources != null &&
                    response.ResourceSets[0].Resources.Length > 0)
                {
                    var locationResult        = response.ResourceSets[0].Resources[0] as BingMapsRESTToolkit.Location;
                    DailyChallengeEntry entry = new DailyChallengeEntry()
                    {
                        imageResponse = locationResult.Name,
                        longitude     = float.Parse(locationResult.Point.Coordinates[0].ToString()),
                        latitude      = float.Parse(locationResult.Point.Coordinates[1].ToString())
                    };

                    return(entry);
                }
                throw new Exception("Location not found");
            }
            catch (Exception exp)
            {
                logger.LogError("Error retrieving image: " + exp.Message + ":::" + exp.StackTrace);
                Console.WriteLine("Grrr error: " + exp.Message);
                return(null);
            }
        }
Beispiel #9
0
        internal static async Task <Location> GetCurrentCoordinates(string currentAddressLine, string currentPostalCode)
        {
            var currentLocationCoordinates = new Location {
                Type = "Point"
            };
            var currentAddress = new SimpleAddress {
                AddressLine = currentAddressLine, PostalCode = currentPostalCode
            };

            var geocodeRequest = new GeocodeRequest()
            {
                Address             = currentAddress,
                IncludeIso2         = true,
                IncludeNeighborhood = true,
                MaxResults          = 25,
                BingMapsKey         = BingMapsKey
            };
            var response = await geocodeRequest.Execute();

            if (response != null &&
                response.ResourceSets != null &&
                response.ResourceSets.Length > 0 &&
                response.ResourceSets[0].Resources != null &&
                response.ResourceSets[0].Resources.Length > 0)
            {
                var result = response.ResourceSets[0].Resources[0] as BingMapsRESTToolkit.Location;

                var coords = result.Point.Coordinates;
                if (coords != null && coords.Length == 2)
                {
                    var lat = coords[0];
                    var lng = coords[1];

                    Console.WriteLine($"Geocode Results - Lat: {lat} / Long: {lng}");
                    currentLocationCoordinates.Coordinates.Add(lat);
                    currentLocationCoordinates.Coordinates.Add(lng);
                }
            }

            return(currentLocationCoordinates);
        }
Beispiel #10
0
        public static async Task <Location> GetGeoLoc(string inquery)
        {
            Location retad = new Location();

            var request = new GeocodeRequest()
            {
                Query               = inquery,
                IncludeIso2         = true,
                IncludeNeighborhood = false,
                MaxResults          = 3,
                BingMapsKey         = bmkey
            };

            try
            {
                var response = await request.Execute();

                if (response != null &&
                    response.ResourceSets != null &&
                    response.ResourceSets.Length > 0 &&
                    response.ResourceSets[0].Resources != null &&
                    response.ResourceSets[0].Resources.Length > 0)
                {
                    var qresult = response.ResourceSets[0].Resources[0] as BingMapsRESTToolkit.Location;
                    retad = qresult;
                }
                else
                {
                    retad = null;
                }
            }
            catch
            {
                retad = null;
            }

            return(retad);
        }
Beispiel #11
0
        private async Task <Locations> GetLonAndLatFromAddress(string address, string groupName, int id, string description = "")
        {
            var location = new Locations();
            var request  = new GeocodeRequest
            {
                BingMapsKey = _bingApiKey,
                Query       = address
            };
            var result = await request.Execute();

            if (result.StatusCode == 200)
            {
                var toolkitLocation = (result?.ResourceSets?.FirstOrDefault())
                                      ?.Resources?.FirstOrDefault()
                                      as Location;
                if (null != toolkitLocation && null == toolkitLocation.Point || toolkitLocation.Point.Coordinates.Length <= 0)
                {
                    return(location);
                }
                var latitude  = toolkitLocation.Point.Coordinates[0];
                var longitude = toolkitLocation.Point.Coordinates[1];
                location.Longitude   = longitude;
                location.Latitude    = latitude;
                location.LocationId  = id;
                location.Description = description;
                location.Title       = groupName;
                // 1, "Bhubaneswar","Bhubaneswar, Odisha", 20.296059, 85.824539

                /*
                 * var mapLocation = new Microsoft.Maps.MapControl.WPF.Location(latitude, longitude);
                 * this.userControl11.myMap.SetView(mapLocation, 15);
                 * var p = new Pushpin() { Location = mapLocation, ToolTip = "KLCC Park" };
                 * this.userControl11.myMap.Children.Add(p);*/
                return(location);
            }
            return(location);
        }
Beispiel #12
0
        private static async Task GeocodeAddress(TDayAddress addr, ConcurrentBag <TDayAddress> goodAddr, ConcurrentBag <TDayAddress> badAddr, MsgOut msgOut)
        {
            var bingKey = "Aq4xnynDuADw0OMoyrHEvCrM8VqhI8HlGIusrLdL30LGJBz71X9JtUCMcVU6mj7Y";

            // ServiceManager.Proxy = new WebProxy("http://proxy.research.ge.com:80/");

            var request = new GeocodeRequest()
            {
                Query               = addr.ToAddress(),
                IncludeIso2         = true,
                IncludeNeighborhood = true,
                MaxResults          = 25,
                BingMapsKey         = bingKey
            };
            //Process the request by using the ServiceManager.
            var response = await request.Execute();

            if (response != null &&
                response.ResourceSets != null &&
                response.ResourceSets.Length > 0 &&
                response.ResourceSets[0].Resources != null &&
                response.ResourceSets[0].Resources.Length > 0)
            {
                Location foundAddr = null;

                foreach (var res in response.ResourceSets[0].Resources)
                {
                    if (((Location)res).Address.AdminDistrict == "NY" && ((Location)res).Address.PostalCode != null && ((Location)res).Address.PostalCode.StartsWith("12"))
                    {
                        foundAddr = (Location)res;
                        //if (((Location)res).Address.PostalCode != addr.Zip)
                        //{
                        //    msgOut($"Changed zip: {addr.ToAddress()} {foundAddr.Address.FormattedAddress}");
                        //}
                        break;
                    }
                }
                //var result = response.ResourceSets[0].Resources[0] as Location;

                addr.Restaurant = GetRestaurant(addr.Zip);

                if (foundAddr != null && foundAddr.MatchCodes[0].ToString() == "Good")
                {
                    //addr.Address1 = foundAddr.Address.AddressLine;
                    //addr.City = foundAddr.Address.Locality;
                    //addr.State = foundAddr.Address.AdminDistrict;
                    //addr.Zip = foundAddr.Address.PostalCode;
                    var coords = foundAddr.Point.Coordinates;
                    if (coords != null && coords.Length == 2)
                    {
                        addr.Lat = (float)coords[0];
                        addr.Lon = (float)coords[1];
                    }
                    goodAddr.Add(addr);
                }
                else
                {
                    badAddr.Add(addr);
                }
                //msgOut($"Geocode: {addr} => Results - Code: {result.MatchCodes[0]}\r");
            }
        }