コード例 #1
0
        /// <summary>
        /// Запрос на получения координаты кинотеатра
        /// </summary>
        /// <param name="address"></param>
        private async void GetAddress(string address)
        {
            using (GeocodeServiceClient client = new GeocodeServiceClient("CustomBinding_IGeocodeService"))
            {
                var request = new GeocodeRequest
                {
                    Credentials = new Credentials()
                    {
                        ApplicationId =
                            (App.Current.Resources["MyCredentials"] as ApplicationIdCredentialsProvider).ApplicationId
                    },
                    Culture = "ru",
                    Query   = AddressCinema,
                };
                var filters = new ConfidenceFilter[1];
                filters[0] = new ConfidenceFilter {
                    MinimumConfidence = Confidence.High
                };

                var geocodeOptions = new GeocodeOptions {
                    Filters = filters
                };
                request.Options = geocodeOptions;
                GeocodeResponse = await client.GeocodeAsync(request);
            }
        }
コード例 #2
0
        private GeocodeService.Location GeocodeAddress(string address)
        {
            GeocodeRequest geocodeRequest = new GeocodeRequest();

            // Set the credentials using a valid Bing Maps Key
            geocodeRequest.Credentials = new GeocodeService.Credentials();
            geocodeRequest.Credentials.ApplicationId = "AjKX5fPclkvH3YTYhLImWMour1KISHMrcFVBrXzVsjqwMLiWobOq83esCN1ra0Q0";
            // Set the full address query
            geocodeRequest.Query = address;

            // Set the options to only return high confidence results
            ConfidenceFilter[] filters = new ConfidenceFilter[1];
            filters[0] = new ConfidenceFilter();
            filters[0].MinimumConfidence = GeocodeService.Confidence.High;
            GeocodeOptions geocodeOptions = new GeocodeOptions();

            geocodeOptions.Filters = filters;
            geocodeRequest.Options = geocodeOptions;
            // Make the geocode request
            GeocodeServiceClient geocodeService  = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
            GeocodeResponse      geocodeResponse = geocodeService.Geocode(geocodeRequest);

            if (geocodeResponse.Results.Length > 0)
            {
                if (geocodeResponse.Results[0].Locations.Length > 0)
                {
                    return(geocodeResponse.Results[0].Locations[0]);
                }
            }
            return(null);
        }
コード例 #3
0
        public void ScoreDifferenceCalculatedWhenSuggestFalse()
        {
            // these are sorted out of the TopNList by the CandidateComparer
            var candidates = new List <Candidate>
            {
                new Candidate
                {
                    Address     = "top match",
                    Score       = 100,
                    Weight      = 0,
                    AddressGrid = "Grid",
                    Location    = new Location(0, 0)
                },
                new Candidate
                {
                    Address     = "top suggestion",
                    Score       = 90.87,
                    Weight      = 0,
                    AddressGrid = "Grid"
                },
                new Candidate
                {
                    Address     = "suggestion",
                    Score       = 80.87,
                    Weight      = 0,
                    AddressGrid = "Grid"
                },
                new Candidate
                {
                    Address     = "another suggestion",
                    Score       = 70.87,
                    Weight      = 0,
                    AddressGrid = "Grid"
                }
            };

            var options = new GeocodeOptions
            {
                ScoreDifference = true
            };

            var address = new GeocodeAddress(new CleansedAddress("", 0, 0, 0, Direction.None, "", StreetType.None, Direction.None, 0, 0, false, false))
            {
                AddressGrids = new List <GridLinkable>
                {
                    new PlaceGridLink("City", "Grid", 0)
                }
            };

            var command = new ChooseBestAddressCandidateCommand(candidates,
                                                                options,
                                                                "top match",
                                                                "test",
                                                                address);

            command.Run();
            var match = command.Result;

            Assert.That(Math.Round(match.ScoreDifference), Is.EqualTo(Math.Round(100 - 90.87)));
        }
コード例 #4
0
        private GeocodeServices.Location GeocodeAddress(string address)
        {
            GeocodeRequest geocodeRequest = new GeocodeRequest();

            // Set the credentials using a valid Bing Maps Key
            geocodeRequest.Credentials = new GeocodeServices.Credentials();
            geocodeRequest.Credentials.ApplicationId = "7Xe5dWLJW6JIhH6jDYR7~6wrgqqAAstaYhxwKEyAB6g~AhB0MhPMBgrTWhG-cxBqbFxaJe92xk7oGVnJPfBckupM4wWTauJQIMkjs5Fs_Z5u";
            // Set the full address query
            geocodeRequest.Query = address;

            // Set the options to only return high confidence results
            ConfidenceFilter[] filters = new ConfidenceFilter[1];
            filters[0] = new ConfidenceFilter();
            filters[0].MinimumConfidence = GeocodeServices.Confidence.High;
            GeocodeOptions geocodeOptions = new GeocodeOptions();

            geocodeOptions.Filters = filters;
            geocodeRequest.Options = geocodeOptions;
            // Make the geocode request
            GeocodeServiceClient geocodeService  = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
            GeocodeResponse      geocodeResponse = geocodeService.Geocode(geocodeRequest);

            if (geocodeResponse.Results.Length > 0)
            {
                if (geocodeResponse.Results[0].Locations.Length > 0)
                {
                    return(geocodeResponse.Results[0].Locations[0]);
                }
            }
            return(null);
        }
コード例 #5
0
        private GeocodeServices.Location GeocodeAddress(string address)
        {
            GeocodeRequest geocodeRequest = new GeocodeRequest();

            // Set the credentials using a valid Bing Maps Key
            geocodeRequest.Credentials = new GeocodeServices.Credentials();
            geocodeRequest.Credentials.ApplicationId = "AhjlMbKnHDlgTASkyk750YRs5wR3_1gN2hEz6pahnE7Iiurq_DzrE4hDUgBxrtfN";
            // Set the full address query
            geocodeRequest.Query = address;

            // Set the options to only return high confidence results
            ConfidenceFilter[] filters = new ConfidenceFilter[1];
            filters[0] = new ConfidenceFilter();
            filters[0].MinimumConfidence = GeocodeServices.Confidence.High;
            GeocodeOptions geocodeOptions = new GeocodeOptions();

            geocodeOptions.Filters = filters;
            geocodeRequest.Options = geocodeOptions;
            // Make the geocode request
            GeocodeServiceClient geocodeService  = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
            GeocodeResponse      geocodeResponse = geocodeService.Geocode(geocodeRequest);

            if (geocodeResponse.Results.Length > 0)
            {
                if (geocodeResponse.Results[0].Locations.Length > 0)
                {
                    return(geocodeResponse.Results[0].Locations[0]);
                }
            }
            return(null);
        }
コード例 #6
0
        public GetAltNameLocatorsForAddressCommand(GeocodeAddress address, GeocodeOptions options)
        {
            Host    = ConfigurationManager.AppSettings["gis_server_host"];
            Address = address;
            Options = options;

            BuildAddressPermutations();
            BuildLocatorLookup();
        }
コード例 #7
0
        public override DireccionPunto GetCoordenadas(string direccion)
        {
            try
            {
                double lat, lon;

                // Asignamos las opciones
                ConfidenceFilter[] filters = new ConfidenceFilter[1];
                filters[0] = new ConfidenceFilter();
                filters[0].MinimumConfidence = GeocodeService.Confidence.High;

                // Añadimos los filtros
                GeocodeOptions geocodeOptions = new GeocodeOptions();
                geocodeOptions.Filters = filters;
                geocodeRequest.Options = geocodeOptions;

                geocodeRequest.Query = direccion;

                // Realizamos la petición
                GeocodeServiceClient geocodeService  = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
                GeocodeResponse      geocodeResponse = geocodeService.Geocode(geocodeRequest);
                DireccionPunto       dp = new DireccionPunto();

                if (geocodeResponse.Results.Length > 0)
                {
                    lat               = geocodeResponse.Results[0].Locations[0].Latitude;
                    lon               = geocodeResponse.Results[0].Locations[0].Longitude;
                    dp.Direccion      = direccion;
                    dp.Latitud        = lat;
                    dp.Longitud       = lon;
                    dp.Pais           = geocodeResponse.Results[0].Address.CountryRegion;
                    dp.NivelRegional2 = geocodeResponse.Results[0].Address.District;
                    dp.NivelRegional1 = geocodeResponse.Results[0].Address.AdminDistrict;
                    dp.Municipio      = geocodeResponse.Results[0].Address.Locality;
                }
                else
                {
                    dp.Latitud  = double.NaN;
                    dp.Longitud = double.NaN;
                }
                utm30Ntransformacion(dp);
                dp.IsGeocodificado = true;
                return(dp);
            }
            catch (Exception ex)
            {
                RaiseMensajeEvent("Bing MAPS - " + ex.Message);
                return(null);
            }
        }
コード例 #8
0
        void GeocodeAddress(string address)
        {
            var geocodeRequest = new GeocodeRequest
            {
                Credentials = new Credentials
                {
                    ApplicationId = App.Self.APIKEY,
                },
                Query   = address,
                Address = new Address()
            };

            var filters = new ConfidenceFilter[1];

            filters[0] = new ConfidenceFilter();
            filters[0].MinimumConfidence = Confidence.High;

            var geocodeOptions = new GeocodeOptions
            {
                Filters = filters
            };

            geocodeRequest.Options = geocodeOptions;

            var geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");

            var myLoc = new Location();

            geocodeService.GeocodeCompleted += async(object sender, GeocodeCompletedEventArgs e) =>
            {
                if (e.Error == null)
                {
                    var res = e.Result;
                    if (e.Result.Results.Length > 0)
                    {
                        if (e.Result.Results[0].Locations.Length > 0)
                        {
                            myLoc = e.Result.Results[0].Locations[0];
                            var uri = await Map.GetMapUri(myLoc.Latitude, myLoc.Longitude, 2, "HYBRID", 300, 300);

                            await Navigation.PushAsync(new Map(uri));
                        }
                    }
                }
            };

            geocodeService.GeocodeAsync(geocodeRequest);
        }
コード例 #9
0
        public static geoResponse geocodeAddress(string address)
        {
            geoResponse results = new geoResponse();

            results.message = "No Results Found";

            results.status = "fail";
            if (!string.IsNullOrEmpty(address.Trim()))
            {
                // get key from configuration
                string key = "ApjKKP3xo-UePHYy4EWVj7kzRUAx40rbKSGGCzw-E_jK2YAtyhs5Na0_PunRgr2Y";


                GeocodeRequest geocodeRequest = new GeocodeRequest();

                // Set the credentials using a valid Bing Maps key
                geocodeRequest.Credentials = new bingMapGeocodeService.Credentials();
                geocodeRequest.Credentials.ApplicationId = key;

                // Set the full address query
                geocodeRequest.Query = address;

                // Set the options to only return high confidence results
                ConfidenceFilter[] filters = new ConfidenceFilter[1];
                filters[0] = new ConfidenceFilter();
                filters[0].MinimumConfidence = bingMapGeocodeService.Confidence.High;

                // Add the filters to the options
                GeocodeOptions geocodeOptions = new GeocodeOptions();
                geocodeOptions.Filters = filters;
                geocodeRequest.Options = geocodeOptions;

                // Make the geocode request
                GeocodeServiceClient geocodeService  = new GeocodeServiceClient();
                GeocodeResponse      geocodeResponse = geocodeService.Geocode(geocodeRequest);

                if (geocodeResponse.Results.Length > 0)
                {
                    results.latitude = geocodeResponse.Results[0].Locations[0].Latitude.ToString();

                    results.longitude = geocodeResponse.Results[0].Locations[0].Longitude.ToString();

                    results.status = "ok";
                }
            }

            return(results);
        }
コード例 #10
0
        public string GeocodeAddress( string address )
        {
            try
            {
                string results = "";
                string key = "AplxUm9o3hkw6qCXBbp61H7HYlDrz-qz8ldgKLJ8Udjd8MFNJAfxxy2IWrfd4bw8";
                GeocodeRequest geocodeRequest = new GeocodeRequest();

                // Set the credentials using a valid Bing Maps key
                geocodeRequest.Credentials = new GeocodeService.Credentials();
                geocodeRequest.Credentials.ApplicationId = key;

                // Set the full address query
                geocodeRequest.Query = address;

                // Set the options to only return high confidence results 
                ConfidenceFilter[] filters = new ConfidenceFilter[1];
                filters[0] = new ConfidenceFilter();
                filters[0].MinimumConfidence = GeocodeService.Confidence.Medium;

                // Add the filters to the options
                GeocodeOptions geocodeOptions = new GeocodeOptions();
                geocodeOptions.Filters = filters;
                geocodeRequest.Options = geocodeOptions;

                // Make the geocode request
                GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
                GeocodeResponse geocodeResponse = geocodeService.Geocode(geocodeRequest);

                if (geocodeResponse.Results.Length > 0)
                {
                    Latitude = geocodeResponse.Results[0].Locations[0].Latitude;
                    Longitude = geocodeResponse.Results[0].Locations[0].Longitude;
                    results = String.Format("Latitude: {0}\nLongitude: {1}", Latitude, Longitude);
                }
                else
                {
                    results = "No Results Found";
                }

                return results;
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
            
        }
コード例 #11
0
        private GeocodeResponse GeocodeAddress(string address)
        {
            var geocodeRequest = new GeocodeRequest();

            geocodeRequest.Credentials = new GeoService.Credentials();
            geocodeRequest.Credentials.ApplicationId = Properties.Resources.BingKey;
            geocodeRequest.Query = address;

            var geocodeOptions = new GeocodeOptions();

            geocodeRequest.Options = geocodeOptions;

            IGeocodeService geoService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");

            return(geoService.Geocode(geocodeRequest));
        }
コード例 #12
0
        public void ScoreDifferenceDoesNotCalculatedWhenSuggestIsGreatherThanZero()
        {
            var candidates = new List <Candidate>
            {
                new Candidate
                {
                    Address     = "top match",
                    Score       = 100,
                    Weight      = 0,
                    AddressGrid = "Grid",
                    Location    = new Location(0, 0)
                },
                new Candidate
                {
                    Address     = "top suggestion",
                    Score       = 90.87,
                    Weight      = 0,
                    AddressGrid = "Grid"
                }
            };

            var options = new GeocodeOptions
            {
                SuggestCount = 1
            };

            var address = new GeocodeAddress(new CleansedAddress("", 0, 0, 0, Direction.None, "", StreetType.None, Direction.None, 0, 0, false, false))
            {
                AddressGrids = new List <GridLinkable>
                {
                    new PlaceGridLink("City", "Grid", 0)
                }
            };

            var command = new ChooseBestAddressCandidateCommand(candidates,
                                                                options,
                                                                "top match",
                                                                "test",
                                                                address);

            command.Run();
            var match = command.Result;

            Assert.That(match.Score, Is.EqualTo(100));
            Assert.That(match.Candidates.Length, Is.EqualTo(1));
            Assert.That(match.ScoreDifference, Is.EqualTo(-1));
        }
コード例 #13
0
        public static geoResponse geocodeAddress(string address)
        {
            geoResponse results = new geoResponse();

            results.message = "No Results Found";

            results.status = "fail";
            if (!string.IsNullOrEmpty(address.Trim())) {

                // get key from configuration
                string key = "ApjKKP3xo-UePHYy4EWVj7kzRUAx40rbKSGGCzw-E_jK2YAtyhs5Na0_PunRgr2Y";

                GeocodeRequest geocodeRequest = new GeocodeRequest();

                // Set the credentials using a valid Bing Maps key
                geocodeRequest.Credentials = new bingMapGeocodeService.Credentials();
                geocodeRequest.Credentials.ApplicationId = key;

                // Set the full address query
                geocodeRequest.Query = address;

                // Set the options to only return high confidence results
                ConfidenceFilter[] filters = new ConfidenceFilter[1];
                filters[0] = new ConfidenceFilter();
                filters[0].MinimumConfidence = bingMapGeocodeService.Confidence.High;

                // Add the filters to the options
                GeocodeOptions geocodeOptions = new GeocodeOptions();
                geocodeOptions.Filters = filters;
                geocodeRequest.Options = geocodeOptions;

                // Make the geocode request
                GeocodeServiceClient geocodeService = new GeocodeServiceClient();
                GeocodeResponse geocodeResponse = geocodeService.Geocode(geocodeRequest);

                if (geocodeResponse.Results.Length > 0) {
                    results.latitude = geocodeResponse.Results[0].Locations[0].Latitude.ToString();

                    results.longitude = geocodeResponse.Results[0].Locations[0].Longitude.ToString();

                    results.status = "ok";
                }
            }

            return results;
        }
コード例 #14
0
        public string GetLocation(string address)
        {
            //Set up some variables
            string results = "";
            string key     = "{Your Bing Key}";

            try
            {
                //Create the geocode request, set the access key and the address to query
                GeocodeRequest geocodeRequest = new GeocodeRequest();
                geocodeRequest.Credentials = new GeocodeService.Credentials();
                geocodeRequest.Credentials.ApplicationId = key;
                geocodeRequest.Query = address;

                //Create a filter to return only high confidence results
                ConfidenceFilter[] filters = new ConfidenceFilter[1];
                filters[0] = new ConfidenceFilter();
                filters[0].MinimumConfidence = Confidence.High;

                //Apply the filter to the request
                GeocodeOptions options = new GeocodeOptions();
                options.Filters        = filters;
                geocodeRequest.Options = options;

                //Make the request
                GeocodeServiceClient client   = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
                GeocodeResponse      response = client.Geocode(geocodeRequest);

                if (response.Results.Length > 0)
                {
                    results = String.Format("Success: {0}:{1}",
                                            response.Results[0].Locations[0].Latitude,
                                            response.Results[0].Locations[0].Longitude);
                }
                else
                {
                    results = "No Results Found";
                }
            }
            catch (Exception e)
            {
                results = "Geocoding Error: " + e.Message;
            }
            return(results);
        }
コード例 #15
0
        public string GetLocation(string address)
        {
            string results = string.Empty;
            string key = "AsPcip7ChAzloBDBmSBoyyrjUgPL4PPigzM8-1rCIWLS5H5WGUJZyXZ971zqXACO";
            try
            {
                //Create the geocode request, set the access key and the address to query
                GeocodeRequest geocodeRequest = new GeocodeRequest();
                geocodeRequest.Credentials = new LocationChecker.GeocodeService.Credentials();
                geocodeRequest.Credentials.ApplicationId = key;
                geocodeRequest.Query = address;

                //Create a filter to return only high confidence results
                ConfidenceFilter[] filters = new ConfidenceFilter[1];
                filters[0] = new ConfidenceFilter();
                filters[0].MinimumConfidence = Confidence.High;

                //Apply the filter to the request
                GeocodeOptions options = new GeocodeOptions();
                //options.Filters = filters;
                geocodeRequest.Options = options;

                //Make the request
                GeocodeServiceClient client = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
                GeocodeResponse response = client.Geocode(geocodeRequest);

                if (response.Results.Length > 0)
                {
                    results = String.Format("Success:{0}:{1}:{2}",
                        response.Results[0].Locations[0].Latitude,
                        response.Results[0].Locations[0].Longitude,
                        response.Results[0].Locations[0].Altitude);
                }
                else
                {
                    results = "No Results Found";
                }
            }
            catch (Exception e)
            {
                results = "Geocoding Error: " + e.Message;
            }
            return results;
        }
コード例 #16
0
        public Double[] GeocodeAddress(string address)
        {
            double[] re;

            GeocodeRequest geocodeRequest = new GeocodeRequest();

            re = new double[2];
            // Set the credentials using a valid Bing Maps key
            geocodeRequest.Credentials = new Microsoft.Maps.MapControl.WPF.Credentials();
            geocodeRequest.Credentials.ApplicationId = key;

            // Set the full address query
            geocodeRequest.Query = address;

            // Set the options to only return high confidence results
            ConfidenceFilter[] filters = new ConfidenceFilter[1];
            filters[0] = new ConfidenceFilter();
            filters[0].MinimumConfidence = GeocodeService.Confidence.High;

            // Add the filters to the options
            GeocodeOptions geocodeOptions = new GeocodeOptions();

            geocodeOptions.Filters = filters;
            geocodeRequest.Options = geocodeOptions;

            // Make the geocode request
            GeocodeServiceClient geocodeService  = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
            GeocodeResponse      geocodeResponse = geocodeService.Geocode(geocodeRequest);

            if (geocodeResponse.Results.Length > 0)
            {
                re[0] = geocodeResponse.Results[0].Locations[0].Latitude;
                re[1] = geocodeResponse.Results[0].Locations[0].Longitude;
                return(re);
            }
            else
            {
                re[0] = 0.0;
                re[1] = 0.0;
                return(re);
            }
            return(re);
        }
コード例 #17
0
        public void IgnoresNoGrid()
        {
            var candidates = new List <Candidate>
            {
                new Candidate
                {
                    Address  = "top match",
                    Score    = 100,
                    Weight   = 0,
                    Location = new Location(0, 0)
                },
                new Candidate
                {
                    Address     = "top suggestion",
                    Score       = 90.87,
                    Weight      = 0,
                    AddressGrid = "GRID",
                    Location    = new Location(0, 0)
                }
            };

            var options = new GeocodeOptions();

            var address = new GeocodeAddress(new CleansedAddress("", 0, 0, 0, Direction.None, "", StreetType.None, Direction.None, 0, 0, false, false))
            {
                AddressGrids = new List <GridLinkable>
                {
                    new PlaceGridLink("City", "GrId", 0)
                }
            };

            var command = new ChooseBestAddressCandidateCommand(candidates,
                                                                options,
                                                                "top match",
                                                                "test",
                                                                address);

            command.Run();
            var match = command.Result;

            Assert.That(match.Score, Is.EqualTo(90.87));
        }
コード例 #18
0
    private String GeocodeAddress(string address)
    {
        string         results        = "";
        string         key            = "ArLeGdHOcc5h7j3L4W37oFGcU9E-LF3tAZi4o0DfhXbPJ8aiyTGbIDNHex08R2u7";
        GeocodeRequest geocodeRequest = new GeocodeRequest();

        // Set the credentials using a valid Bing Maps key
        geocodeRequest.Credentials = new GeocodeService.Credentials();
        geocodeRequest.Credentials.ApplicationId = key;

        // Set the full address query
        geocodeRequest.Query = address;

        // Set the options to only return high confidence results
        ConfidenceFilter[] filters = new ConfidenceFilter[1];
        filters[0] = new ConfidenceFilter();
        filters[0].MinimumConfidence = GeocodeService.Confidence.High;

        // Add the filters to the options
        GeocodeOptions geocodeOptions = new GeocodeOptions();

        geocodeOptions.Filters = filters;
        geocodeRequest.Options = geocodeOptions;

        // Make the geocode request
        GeocodeServiceClient geocodeService  = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
        GeocodeResponse      geocodeResponse = geocodeService.Geocode(geocodeRequest);

        if (geocodeResponse.Results.Length > 0)
        {
            results = String.Format("Latitude: {0}\nLongitude: {1}",
                                    geocodeResponse.Results[0].Locations[0].Latitude,
                                    geocodeResponse.Results[0].Locations[0].Longitude);
        }
        else
        {
            results = "No Results Found";
        }

        return(results);
    }
コード例 #19
0
ファイル: MainWindow.xaml.cs プロジェクト: Yasmine2017/bing
        //The Geocode Service
        private String GeocodeAddress(string address)
        {
            string         results        = "";
            string         key            = "ApwndqJgdJ9M1Bpb7d_ihBwXW-J0N3HdXrZvFZqvFtmeYN5DewRoGPI7czgFo5Sh";
            GeocodeRequest geocodeRequest = new GeocodeRequest();

            // Set the credentials using a valid Bing Maps key
            geocodeRequest.Credentials = new GeocodeService.Credentials();
            geocodeRequest.Credentials.ApplicationId = key;

            // Set the full address query
            geocodeRequest.Query = address;

            // Set the options to only return high confidence results
            ConfidenceFilter[] filters = new ConfidenceFilter[1];
            filters[0] = new ConfidenceFilter();
            filters[0].MinimumConfidence = GeocodeService.Confidence.High;

            // Add the filters to the options
            GeocodeOptions geocodeOptions = new GeocodeOptions();

            geocodeOptions.Filters = filters;
            geocodeRequest.Options = geocodeOptions;

            // Make the geocode request
            GeocodeServiceClient geocodeService  = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
            GeocodeResponse      geocodeResponse = geocodeService.Geocode(geocodeRequest);

            if (geocodeResponse.Results.Length > 0)
            {
                results = String.Format("Latitude: {0}\nLongitude: {1}",
                                        geocodeResponse.Results[0].Locations[0].Latitude,
                                        geocodeResponse.Results[0].Locations[0].Longitude);
            }
            else
            {
                results = "No Results Found";
            }

            return(results);
        }
コード例 #20
0
        //Find the location by address
        private void GeocodeAddress(string address)
        {
            string         results        = "";
            string         key            = "AnYws_sa62sPmXR-zcq6XDp8P9Sbtvbv3Bi3FtXkKc4jvOjmNwD3SeaHz54pAxpg";
            GeocodeRequest geocodeRequest = new GeocodeRequest();

            // Set the credentials using a valid Bing Maps key
            geocodeRequest.Credentials = new Microsoft.Maps.MapControl.WPF.Credentials();
            geocodeRequest.Credentials.ApplicationId = key;

            // Set the full address query
            geocodeRequest.Query = address;

            // Set the options to only return high confidence results
            ConfidenceFilter[] filters = new ConfidenceFilter[1];
            filters[0] = new ConfidenceFilter();
            filters[0].MinimumConfidence = GeocodeService.Confidence.High;

            // Add the filters to the options
            GeocodeOptions geocodeOptions = new GeocodeOptions();

            geocodeOptions.Filters = filters;
            geocodeRequest.Options = geocodeOptions;

            // Make the geocode request
            GeocodeServiceClient geocodeService  = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
            GeocodeResponse      geocodeResponse = geocodeService.Geocode(geocodeRequest);

            if (geocodeResponse.Results.Length > 0)
            {
                results = String.Format("Latitude: {0}\nLongitude: {1}",
                                        geocodeResponse.Results[0].Locations[0].Latitude,
                                        geocodeResponse.Results[0].Locations[0].Longitude);
                PlacePin(geocodeResponse.Results[0].Locations[0].Latitude, geocodeResponse.Results[0].Locations[0].Longitude);
            }
            else
            {
                results = "No Results Found";
            }
        }
コード例 #21
0
        public ChooseBestAddressCandidateCommand(IEnumerable <Candidate> candidates, GeocodeOptions geocodeOptions,
                                                 string street, string zone, GeocodeAddress geocodedAddress)
        {
            GeocodeOptions  = geocodeOptions;
            Street          = street;
            Zone            = zone;
            GeocodedAddress = geocodedAddress;

            if (candidates == null)
            {
                candidates = new List <Candidate>();
            }

            var enumerable = candidates as IList <Candidate> ?? candidates.ToList();

            foreach (var candidate in enumerable)
            {
                candidate.ScoreDifference = -1;
            }

            Candidates = enumerable.ToList();
        }
コード例 #22
0
        public void ScoreDifferenceCalculatedWhenSuggestFalseAndNoSuggestions()
        {
            var candidates = new List <Candidate>
            {
                new Candidate
                {
                    Address     = "top match",
                    Score       = 100,
                    Weight      = 0,
                    AddressGrid = "Grid",
                    Location    = new Location(0, 0)
                }
            };

            var options = new GeocodeOptions
            {
                ScoreDifference = true
            };

            var address = new GeocodeAddress(new CleansedAddress("", 0, 0, 0, Direction.None, "", StreetType.None, Direction.None, 0, 0, false, false))
            {
                AddressGrids = new List <GridLinkable>
                {
                    new PlaceGridLink("City", "Grid", 0)
                }
            };

            var command = new ChooseBestAddressCandidateCommand(candidates,
                                                                options,
                                                                "top match",
                                                                "test",
                                                                address);

            command.Run();
            var match = command.Result;

            Assert.That(match.ScoreDifference, Is.EqualTo(-1));
        }
コード例 #23
0
        /// <summary>
        /// Calls bing maps api to geocode address specified in string parametr.
        /// </summary>
        /// <param name="address"></param>
        /// <param name="handler"></param>
        public void GeocodeAddress(string address, EventHandler <GeocodeCompletedEventArgs> handler)
        {
            //if no address was specified, ignore it
            if (address == null || address == String.Empty)
            {
                return;
            }

            GeocodeRequest geocodeRequest = new GeocodeRequest();

            // Set the credentials using a valid Bing Maps key
            geocodeRequest.Credentials = new Credentials();
            geocodeRequest.Credentials.ApplicationId = _applicationID;

            // Set the full address query
            geocodeRequest.Query = address;

            // Set the options to only return high confidence results
            ConfidenceFilter filter = new ConfidenceFilter();

            filter.MinimumConfidence = GeocodeService.Confidence.High;
            ObservableCollection <FilterBase> filtersCol = new ObservableCollection <FilterBase>();

            filtersCol.Add(filter);


            // Add the filters to the options
            GeocodeOptions geocodeOptions = new GeocodeOptions();

            geocodeOptions.Filters = filtersCol;
            geocodeRequest.Options = geocodeOptions;

            // Make the geocode request
            GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");

            geocodeService.GeocodeCompleted += handler;
            geocodeService.GeocodeAsync(geocodeRequest);
        }
コード例 #24
0
ファイル: Form1.cs プロジェクト: usmanghani/Misc
        private void button1_Click(object sender, EventArgs e)
        {
            CommonService tokenService = new CommonService();
            tokenService.Credentials = new System.Net.NetworkCredential("137871", "Mugga25.");
            TokenSpecification tokenSpecs = new TokenSpecification();
            tokenSpecs.ClientIPAddress = "0.0.0.0   ";
            tokenSpecs.TokenValidityDurationMinutes = 60;
            string token = tokenService.GetClientToken(tokenSpecs);
            textBox1.AppendText(token + Environment.NewLine);
            GeocodeRequest request = new GeocodeRequest();
            request.Credentials = new Credentials();
            request.Credentials.Token = token;
            request.Query = "1234";
            GeocodeOptions options = new GeocodeOptions();
            ConfidenceFilter[] filters = new ConfidenceFilter[] { new ConfidenceFilter() { MinimumConfidence = Confidence.Low } };
            options.Filters = filters;
            request.Options = options;
            GeocodeServiceClient geoCoder = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
            GeocodeResponse response = geoCoder.Geocode(request);
            foreach (var result in response.Results)
            {
                textBox1.AppendText("Display Name: " + result.DisplayName + Environment.NewLine);
                textBox1.AppendText("Confidence: " + result.Confidence.ToString() + Environment.NewLine);
                textBox1.AppendText("Entity Type: " + result.EntityType + Environment.NewLine);
                foreach (var location in result.Locations)
                {
                    textBox1.AppendText("Longitude: " + location.Longitude + Environment.NewLine);
                    textBox1.AppendText("Latitude: " + location.Latitude + Environment.NewLine);
                    textBox1.AppendText("Altitude: " + location.Altitude + Environment.NewLine);
                }
            }

            //LiveMapsTokenService.CommonServiceSoapClient tokenService = new LiveMapsTest.LiveMapsTokenService.CommonServiceSoapClient("CommonServiceSoap");
            //GetClientTokenRequest tokenRequest = new GetClientTokenRequest();
            //tokenService.ClientCredentials.UserName.UserName = "******";
            //tokenService.ClientCredentials.UserName.Password = "******";
        }
コード例 #25
0
        public geoloc GeocodeAddress(string address)
        {
            GeocodeRequest geocodeRequest = new GeocodeRequest();

            // Set the credentials using a valid Bing Maps key
            geocodeRequest.Credentials = new GeoCodeService.Credentials();
            geocodeRequest.Credentials.ApplicationId = "AiIo0eq8yDzQx40gwHidcSJzTIZjanj36I5v_xVhbNCuB-3GTeJ0tkTM2c7exntM";

            // Set the full address query
            geocodeRequest.Query = address;

            // Set the options to only return high confidence results
            ConfidenceFilter[] filters = new ConfidenceFilter[1];
            filters[0] = new ConfidenceFilter();
            filters[0].MinimumConfidence = GeoCodeService.Confidence.Low;

            // Add the filters to the options
            GeocodeOptions geocodeOptions = new GeocodeOptions();
            geocodeOptions.Filters = filters;
            geocodeRequest.Options = geocodeOptions;

            // Make the geocode request
            GeoCodeService.GeocodeServiceClient geocodeService = new GeoCodeService.GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
            GeocodeResponse geocodeResponse = geocodeService.Geocode(geocodeRequest);

            if (geocodeResponse.Results.Length > 0)
            {
                geoloc res = new geoloc();
                res.lat = geocodeResponse.Results[0].Locations[0].Latitude;
                res.lon = geocodeResponse.Results[0].Locations[0].Longitude;

                return res;
            }
            else
                throw new Exception("No Results Found");
        }
コード例 #26
0
ファイル: Form1.cs プロジェクト: whoisjohngalt83/csharp-proj
 private GeocodeResponse GeoCodeData(string address)
 {
     try
     {
         GeocodeRequest request = new GeocodeRequest();
         request.Credentials = new GeocodeService.Credentials();
         request.Credentials.ApplicationId = getConfig("BingApiKey");
         request.Query = address;
         ConfidenceFilter[] filters = new ConfidenceFilter[1];
         filters[0] = new ConfidenceFilter();
         filters[0].MinimumConfidence = GeocodeService.Confidence.High;
         GeocodeOptions geocodeOptions = new GeocodeOptions();
         geocodeOptions.Filters = filters;
         request.Options        = geocodeOptions;
         GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
         GeocodeResponse      response       = geocodeService.Geocode(request);
         if (response.Results.Length > 0)
         {
             return(response);
         }
     }
     catch { }
     return(null);
 }
コード例 #27
0
        private GeocodeService.Location GeocodeAddressGetLocation(string address)
        {
            string key = "l4o5yybDpLNG7xrsTmoP~A0DSZhcYTwcaKvEUgBi44g~AsAjqiCU7gZND03eLCfpdqNDGFXfMdzqXYLFVEGnFy1SgQSlDA8ld0BpbCgI4JsD";
            GeocodeRequest geocodeRequest = new GeocodeRequest();

            // Set the credentials using a valid Bing Maps key
            geocodeRequest.Credentials = new GeocodeService.Credentials();
            geocodeRequest.Credentials.ApplicationId = key;

            // Set the full address query
            geocodeRequest.Query = address;

            // Set the options to only return high confidence results
            ConfidenceFilter[] filters = new ConfidenceFilter[1];
            filters[0] = new ConfidenceFilter();
            filters[0].MinimumConfidence = GeocodeService.Confidence.High;

            // Add the filters to the options
            GeocodeOptions geocodeOptions = new GeocodeOptions();
            geocodeOptions.Filters = filters;
            geocodeRequest.Options = geocodeOptions;

            // Make the geocode request
            GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
            GeocodeResponse geocodeResponse;
            try
            {
                geocodeResponse = geocodeService.Geocode(geocodeRequest);
            }
            catch
            {
                MapLabelTextBox.Text = "Adresse non trouvée";
                return null;
            }

            if (geocodeResponse.Results.Length > 0)
            {
                latitude = geocodeResponse.Results[0].Locations[0].Latitude.ToString();
                longitude = geocodeResponse.Results[0].Locations[0].Longitude.ToString();
                MapLabelTextBox.Text = address;
                return geocodeResponse.Results[0].Locations[0];
            }
            else
            {
                MapLabelTextBox.Text = "Adresse non trouvée";
                latitude = null;
                longitude = null;
                return null;
            }
        }
コード例 #28
0
 public PoBoxCommand(GeocodeAddress geocodeAddress, GeocodeOptions options)
 {
     _options        = options;
     GeocodedAddress = geocodeAddress;
 }
コード例 #29
0
 public OrchesrateeGeocodeCommand(string street, string zone, GeocodeOptions options)
 {
     Street  = street;
     Zone    = zone;
     Options = options;
 }
コード例 #30
0
        private LatLonPair DoBingGeocoding(string query)
        {
            try
            {
                var mappingCredentials = _settingsManager.GetString(Common.Constants.MappingApplicationId, Common.Constants.BingMapsKey);

                var geocodeRequest = new MEDSEEK.eHealth.Utils.Business.GeoCodeService.GeocodeRequest();
                geocodeRequest.Credentials = new MEDSEEK.eHealth.Utils.Business.GeoCodeService.Credentials();
                geocodeRequest.Credentials.ApplicationId = mappingCredentials;
                geocodeRequest.Query = query;

                // Set the options to only return high confidence results
                ConfidenceFilter[] filters = new ConfidenceFilter[1];
                filters[0] = new ConfidenceFilter();
                filters[0].MinimumConfidence = MEDSEEK.eHealth.Utils.Business.GeoCodeService.Confidence.High;

                // Add the filters to the options
                GeocodeOptions geocodeOptions = new GeocodeOptions();
                geocodeOptions.Filters = filters;
                geocodeRequest.Options = geocodeOptions;

                // Make the geocode request
                GeocodeResponse geocodeResponse;
                using (var geocodeService = new GeocodeServiceClient())
                {
                    geocodeResponse = geocodeService.Geocode(geocodeRequest);
                }
                if (geocodeResponse.Results.Length > 0)
                {
                    return new LatLonPair()
                    {
                        Latitude = geocodeResponse.Results[0].Locations[0].Latitude.ToString(CultureInfo.InvariantCulture),
                        Longitude = geocodeResponse.Results[0].Locations[0].Longitude.ToString(CultureInfo.InvariantCulture)
                    };
                }
            }
            catch (Exception ex)
            {
                var exception = ex.InnerException != null ? ex.InnerException : ex;
                _logger.Error(ex.Message, exception);
            }
            return null;
        }
コード例 #31
0
ファイル: BingRoutes.cs プロジェクト: rick3500/masonic
        public String GeocodeAddress(string address)
        {
            string results = "";

            GeocodeRequest geocodeRequest = new GeocodeRequest();

            // Set the credentials using a valid Bing Maps key
            geocodeRequest.Credentials = new GeocodeService.Credentials();
            geocodeRequest.Credentials.ApplicationId = key;

            // Set the full address query
            geocodeRequest.Query = address;

            // Set the options to only return high confidence results
            ConfidenceFilter[] filters = new ConfidenceFilter[1];
            filters[0] = new ConfidenceFilter();
            filters[0].MinimumConfidence = GeocodeService.Confidence.High;

            // Add the filters to the options
            GeocodeOptions geocodeOptions = new GeocodeOptions();
            geocodeOptions.Filters = filters;
            geocodeRequest.Options = geocodeOptions;

            // Make the geocode request
            GeocodeServiceClient geocodeService = new GeocodeServiceClient();
            GeocodeResponse geocodeResponse = geocodeService.Geocode(geocodeRequest);

            if (geocodeResponse.Results.Length > 0)
                results = String.Format("Latitude: {0}\nLongitude: {1}",
                  geocodeResponse.Results[0].Locations[0].Latitude,
                  geocodeResponse.Results[0].Locations[0].Longitude);
            else
                results = "No Results Found";

            return results;
        }
コード例 #32
0
 internal void CopyFrom(MatchUISettings other)
 {
     UIOptions      = other?.UIOptions;
     ParseOptions   = other?.ParseOptions;
     GeocodeOptions = other?.GeocodeOptions;
 }
コード例 #33
0
        public HttpResponseMessage Get(string street, string zone, [FromUri] GeocodeOptions options)
        {
            var log        = Log.ForContext <GeocodeController>();
            var geocodeLog = log.ForContext("request-id", $"{street},{zone}");

            geocodeLog.Warning("geocode(single): street {street}, zone {zone}, with {@options}", street, zone, options);

            #region validation

            street = street?.Trim();
            zone   = zone?.Trim();

            zone = zone?.Replace(".", "").Replace(",", "").Replace("_", " ");

            var errors = "";
            if (string.IsNullOrEmpty(street))
            {
                errors = "Street is empty.";
            }

            if (string.IsNullOrEmpty(zone))
            {
                errors += "Zip code or city name is emtpy";
            }

            if (errors.Length > 0)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest,
                                              new ResultContainer <GeocodeAddressResult>
                {
                    Status = (int)HttpStatusCode.BadRequest,
                    Message = errors
                }));
            }

            #endregion

            GeocodeAddressResult geocodeAddressResult;

            try
            {
                geocodeAddressResult =
                    CommandExecutor.ExecuteCommand(new OrchesrateeGeocodeCommand(street, zone, options));
            }
            catch (AggregateException ex)
            {
                geocodeLog.Fatal(ex, "geocode(single): Aggregate error from geocoding");
                return(Request.CreateResponse(HttpStatusCode.InternalServerError,
                                              new ResultContainer <GeocodeAddressResult>
                {
                    Status = (int)HttpStatusCode.InternalServerError,
                    Message = "Geocoding error occured.",
                    Result = new GeocodeAddressResult
                    {
                        InputAddress = $"{street}, {zone}",
                        Score = -9
                    }
                })
                       .AddTypeHeader(typeof(ResultContainer <GeocodeAddressResult>)));
            }
            catch (GeocodingException ex)
            {
                geocodeLog.Fatal(ex, "geocode(single): Geocoding error from geocoding");
                return(Request.CreateResponse(HttpStatusCode.InternalServerError,
                                              new ResultContainer <GeocodeAddressResult>
                {
                    Status = (int)HttpStatusCode.InternalServerError,
                    Message = $"Geocoding error occured. {ex.Message}",
                    Result = new GeocodeAddressResult
                    {
                        InputAddress = $"{street}, {zone}",
                        Score = -9
                    }
                })
                       .AddTypeHeader(typeof(ResultContainer <GeocodeAddressResult>)));
            }
            catch (Exception ex)
            {
                geocodeLog.Fatal(ex, "geocode(single): Normal error from geocoding");
                return(Request.CreateResponse(HttpStatusCode.InternalServerError,
                                              new ResultContainer <GeocodeAddressResult>
                {
                    Status = (int)HttpStatusCode.InternalServerError,
                    Message = $"Geocoding error occured.",
                    Result = new GeocodeAddressResult
                    {
                        InputAddress = $"{street}, {zone}",
                        Score = -9
                    }
                })
                       .AddTypeHeader(typeof(ResultContainer <GeocodeAddressResult>)));
            }

            if (geocodeAddressResult == null || geocodeAddressResult.Score < 0)
            {
                geocodeLog.Warning("geocode(single): Could not find match for {Street}, {Zone} with a score of {Score} or better.", street, zone,
                                   options.AcceptScore);

                return(Request.CreateResponse(HttpStatusCode.NotFound,
                                              new ResultContainer <GeocodeAddressResult>
                {
                    Status = (int)HttpStatusCode.NotFound,
                    Message = $"No address candidates found with a score of {options.AcceptScore} or better."
                })
                       .AddCache()
                       .AddTypeHeader(typeof(ResultContainer <GeocodeAddressResult>)));
            }

            if (geocodeAddressResult.Location == null)
            {
                geocodeLog.Warning("geocode(single): Could not find match for {Street}, {Zone} with a score of {Score} or better.", street, zone,
                                   options.AcceptScore);
            }

            geocodeAddressResult.Wkid = options.WkId;

            geocodeLog.Warning("geocode(single): success score {score}, {@result}", geocodeAddressResult.Score, geocodeAddressResult);

            var response = Request.CreateResponse(HttpStatusCode.OK,
                                                  new ResultContainer <GeocodeAddressResult>
            {
                Status = (int)HttpStatusCode.OK,
                Result = geocodeAddressResult
            })
                           .AddCache()
                           .AddTypeHeader(typeof(ResultContainer <GeocodeAddressResult>));

            return(response);
        }
コード例 #34
0
        //Find the location by address
        private void GeocodeAddress(string address)
        {
            string results = "";
            string key = "AnYws_sa62sPmXR-zcq6XDp8P9Sbtvbv3Bi3FtXkKc4jvOjmNwD3SeaHz54pAxpg";
            GeocodeRequest geocodeRequest = new GeocodeRequest();

            // Set the credentials using a valid Bing Maps key
            geocodeRequest.Credentials = new Microsoft.Maps.MapControl.WPF.Credentials();
            geocodeRequest.Credentials.ApplicationId = key;

            // Set the full address query
            geocodeRequest.Query = address;

            // Set the options to only return high confidence results 
            ConfidenceFilter[] filters = new ConfidenceFilter[1];
            filters[0] = new ConfidenceFilter();
            filters[0].MinimumConfidence = GeocodeService.Confidence.High;

            // Add the filters to the options
            GeocodeOptions geocodeOptions = new GeocodeOptions();
            geocodeOptions.Filters = filters;
            geocodeRequest.Options = geocodeOptions;

            // Make the geocode request
            GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
            GeocodeResponse geocodeResponse = geocodeService.Geocode(geocodeRequest);

            if (geocodeResponse.Results.Length > 0)
            {
                results = String.Format("Latitude: {0}\nLongitude: {1}",
                  geocodeResponse.Results[0].Locations[0].Latitude,
                  geocodeResponse.Results[0].Locations[0].Longitude);
                PlacePin(geocodeResponse.Results[0].Locations[0].Latitude, geocodeResponse.Results[0].Locations[0].Longitude);
            }
            else
            {
                results = "No Results Found";
            }
        }
コード例 #35
0
        private void StartSearch(string address)
        {
            GeocodeRequest geocodeRequest = new GeocodeRequest();

            // Set the credentials using a valid Bing Maps key
            geocodeRequest.Credentials = new Credentials();
            geocodeRequest.Credentials.ApplicationId = m_BingKey;

            // Set the full address query
            geocodeRequest.Query = address;

            // Set the options to only return high confidence results
            ConfidenceFilter[] filters = new ConfidenceFilter[1];
            filters[0] = new ConfidenceFilter();
            filters[0].MinimumConfidence = GeocodeService.Confidence.High;

            // Add the filters to the options
            GeocodeOptions geocodeOptions = new GeocodeOptions();
            geocodeOptions.Filters = filters;
            geocodeRequest.Options = geocodeOptions;

            ServicePointManager.UseNagleAlgorithm = true;
            // Switch off 100 continue expectation
            ServicePointManager.Expect100Continue = false;
            ServicePointManager.CheckCertificateRevocationList = true;
            ServicePointManager.DefaultConnectionLimit = ServicePointManager.DefaultPersistentConnectionLimit;

            // Make the geocode request
            m_SearchResults.Clear();
            try
            {
                GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
                GeocodeResponse geocodeResponse = geocodeService.Geocode(geocodeRequest);

                foreach (GeocodeService.GeocodeResult r in geocodeResponse.Results)
                {
                    m_SearchResults.Add(r);
                    lwResults.SelectedIndex = 0;
                    btnSendCoords.IsEnabled = (m_SearchResults.Count > 0);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #36
0
        public async Task <GeocodeLocation> ZipCodeToGeoCoordinateAsync(string zipCode, string country = "Denmark")
        {
            var tcs = new TaskCompletionSource <GeocodeLocation>();

            string         address = string.Format("{0}, {1}", zipCode, country);
            GeocodeRequest request = new GeocodeRequest();

            request.Credentials = new Credentials();
            request.Credentials.ApplicationId = Settings.BingmapsAPIKey;
            request.Query = address;

            var filters = new ObservableCollection <FilterBase>();

            filters.Add(new ConfidenceFilter()
            {
                MinimumConfidence = Confidence.Medium
            });
            GeocodeOptions options = new GeocodeOptions();

            options.Filters = filters;
            request.Options = options;


            GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");

            geocodeService.GeocodeCompleted += (object sender, GeocodeCompletedEventArgs e) => {
                if (e.Cancelled)
                {
                    tcs.SetCanceled();
                    return;
                }

                if (e.Error != null)
                {
                    tcs.SetException(e.Error);
                    return;
                }
                if (e.Result == null || !e.Result.Results.Any())
                {
                    tcs.SetResult(null);
                    return;
                }
                var geoCodeResult = e.Result.Results.FirstOrDefault();
                if (geoCodeResult == null)
                {
                    tcs.TrySetResult(null);
                    return;
                }

                if (geoCodeResult.Locations == null || !geoCodeResult.Locations.Any())
                {
                    tcs.TrySetResult(null);
                    return;
                }
                var location = geoCodeResult.Locations.FirstOrDefault();
                if (location == null)
                {
                    tcs.SetResult(null);
                    return;
                }
                tcs.SetResult(location);
            };
            geocodeService.GeocodeAsync(request);
            return(await tcs.Task);
        }
コード例 #37
0
 public GeocodeAddressCommand(GeocodeAddress address, GeocodeOptions geocodingOptions)
 {
     Address          = address;
     GeocodingOptions = geocodingOptions;
 }
コード例 #38
0
        private void TestSearch()
        {
            GeocodeRequest geocodeRequest = new GeocodeRequest();

            // Set the credentials using a valid Bing Maps key
            //geocodeRequest.Credentials = new NErgy.Silverlight.GeocodeService.Credentials();
            geocodeRequest.Credentials.ApplicationId = "AliveLsVdOVnhqNkgV_FToj2KurkqQev_CRld2F-3TRGJMzq5q8ycnNR9REGotXB";

            // Set the full address query
            geocodeRequest.Query = address.Text ;

            ConfidenceFilter[] filters = new ConfidenceFilter[1];
            filters[0] = new ConfidenceFilter();
            filters[0].MinimumConfidence = GeocodeService.Confidence.High;

            GeocodeOptions geocodeOptions = new GeocodeOptions();
            geocodeOptions.Filters = new System.Collections.ObjectModel.ObservableCollection<FilterBase>(filters);

            geocodeRequest.Options = geocodeOptions;

            GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
            geocodeService.GeocodeCompleted += new EventHandler<GeocodeCompletedEventArgs>(geocodeService_GeocodeCompleted);
            geocodeService.GeocodeAsync(geocodeRequest);
        }
コード例 #39
0
        public HttpResponseMessage Multiple(MultipleGeocodeContainerArgs addresseses, [FromUri] GeocodeOptions options)
        {
            var log = Log.ForContext <GeocodeController>();

            log.Warning("geocode(multiple): options {@options}", options);

            var notifications = "";

            #region validation

            if (addresseses == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest,
                                              new ResultContainer <MultipleGeocdeAddressResultContainer>
                {
                    Status = (int)HttpStatusCode.BadRequest,
                    Message =
                        "Could not deserialize json. Please validate json to make sure it is in correct format. Try http://jsonlint.com"
                })
                       .AddCache()
                       .AddTypeHeader(typeof(ResultContainer <MultipleGeocdeAddressResultContainer>)));
            }

            if (!addresseses.Addresses.Any())
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest,
                                              new ResultContainer <MultipleGeocdeAddressResultContainer>
                {
                    Status = (int)HttpStatusCode.BadRequest,
                    Message =
                        "No addresses to geocode. Please validate json to make sure it is in correct format. Try http://jsonlint.com"
                })
                       .AddCache()
                       .AddTypeHeader(typeof(ResultContainer <MultipleGeocdeAddressResultContainer>)));
            }

            if (addresseses.Addresses.Count > MaxAddresses)
            {
                notifications = string.Format("Input {0}/{1} - Only processed {1}. ", addresseses.Addresses.Count,
                                              MaxAddresses);
                addresseses.Addresses = addresseses.Addresses.OrderBy(x => x.Id).Take(MaxAddresses).ToList();
            }

            var duplicateIds = addresseses.Addresses.GroupBy(x => x.Id)
                               .Where(x => x.Count() > 1)
                               .Select(x => x.Key)
                               .ToList();

            if (duplicateIds.Count > 0)
            {
                notifications +=
                    string.Format("Found duplicate id's in list for ({0}). These addresses will not be geocoded.",
                                  string.Join(", ", duplicateIds));
            }

            #endregion

            var batchAddressResults = new Dictionary <int, GeocodeAddressResult>();

            foreach (var address in addresseses.Addresses)
            {
                if (duplicateIds.Contains(address.Id))
                {
                    continue;
                }

                batchAddressResults.Add(address.Id,
                                        CommandExecutor.ExecuteCommand(new OrchesrateeGeocodeCommand(address.Street,
                                                                                                     address.Zone,
                                                                                                     options)));
            }

            var result = new MultipleGeocdeAddressResultContainer
            {
                Addresses = batchAddressResults.Select(MultipleGeocodeAddressResult.MapResult).ToList()
            };

            duplicateIds.ForEach(x => result.Addresses.Add(new MultipleGeocodeAddressResult
            {
                Id           = x,
                Score        = -2,
                ErrorMessage = "Duplicate Id; Skipping."
            }));

            HttpResponseMessage response;
            try
            {
                log.Warning("success(multiple): success count {count}, average score {score}", result.Addresses.Count(), result.Addresses.Select(x => x.Score).Distinct());
                response = Request.CreateResponse(HttpStatusCode.OK,
                                                  new ResultContainer
                                                  <MultipleGeocdeAddressResultContainer>
                {
                    Status  = (int)HttpStatusCode.OK,
                    Message = notifications,
                    Result  = result
                })
                           .AddCache()
                           .AddTypeHeader(typeof(ResultContainer <MultipleGeocdeAddressResultContainer>));
            }
            catch (InvalidOperationException ex)
            {
                log.Fatal(ex, "geocode(multiple): invalid operation jsonp?");

                response = new HttpResponseMessage(HttpStatusCode.BadGateway)
                {
                    Content = new ObjectContent(typeof(ResultContainer), new ResultContainer
                    {
                        Message = "JSONP does not work with POST requests.",
                        Status  = 400
                    }, new JsonMediaTypeFormatter())
                };
            }

            return(response);
        }
コード例 #40
0
 public UspsDeliveryPointCommand(GeocodeAddress geocodeAddress, GeocodeOptions options)
 {
     _options        = options;
     GeocodedAddress = geocodeAddress;
 }
コード例 #41
0
ファイル: ServiceCaller.cs プロジェクト: hoonzis/bikeincity
        /// <summary>
        /// Calls bing maps api to geocode address specified in string parametr.
        /// </summary>
        /// <param name="address"></param>
        /// <param name="handler"></param>
        public void GeocodeAddress(string address, EventHandler<GeocodeCompletedEventArgs> handler)
        {
            //if no address was specified, ignore it
              if (address == null || address == String.Empty)
              {
            return;
              }

              GeocodeRequest geocodeRequest = new GeocodeRequest();

              // Set the credentials using a valid Bing Maps key
              geocodeRequest.Credentials = new Credentials();
              geocodeRequest.Credentials.ApplicationId = _applicationID;

              // Set the full address query
              geocodeRequest.Query = address;

              // Set the options to only return high confidence results
              ConfidenceFilter filter = new ConfidenceFilter();

              filter.MinimumConfidence = GeocodeService.Confidence.High;
              ObservableCollection<FilterBase> filtersCol = new ObservableCollection<FilterBase>();
              filtersCol.Add(filter);

              // Add the filters to the options
              GeocodeOptions geocodeOptions = new GeocodeOptions();
              geocodeOptions.Filters = filtersCol;
              geocodeRequest.Options = geocodeOptions;

              // Make the geocode request
              GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");

              geocodeService.GeocodeCompleted += handler;
              geocodeService.GeocodeAsync(geocodeRequest);
        }
コード例 #42
0
        public static async Task <LocationInformation> ResolveLocationAsync(double latitude, double longitude)
        {
            LocationInformation location = null;

            GeocodeServiceClient geocodeClient = Helpers.BindingManager.GetGeocodeClient();

            ReverseGeocodeRequest geocodeRequest = new ReverseGeocodeRequest();

            // Set the credentials using a valid Bing Maps key
            geocodeRequest.Credentials = new GeocodeService.Credentials();
            geocodeRequest.Credentials.ApplicationId = Core.Common.CoreConstants.BingLocationApiKey;

            // Set the full address query
            geocodeRequest.Location = new GeocodeService.Location()
            {
                Latitude  = latitude,
                Longitude = longitude,
            };

            // Set the options to only return high confidence results
            List <FilterBase> filters = new List <FilterBase>();

            filters.Add(new ConfidenceFilter()
            {
                MinimumConfidence = GeocodeService.Confidence.High,
            });

            GeocodeOptions geocodeOptions = new GeocodeOptions();

            geocodeOptions.Filters = filters;

            GeocodeResponse geocodeResponse = await geocodeClient.ReverseGeocodeAsync(geocodeRequest);

            var result = geocodeResponse.Results.FirstOrDefault();

            GeocodeService.Address  foundAddress  = null;
            GeocodeService.Location foundLocation = null;

            if (result != null)
            {
                foundAddress  = result.Address;
                foundLocation = result.Locations.FirstOrDefault();

                if (foundAddress != null)
                {
                    location = new LocationInformation()
                    {
                        DisplayName   = foundAddress.FormattedAddress,
                        StreetAddress = foundAddress.AddressLine,
                        City          = foundAddress.Locality,
                        PostalCode    = foundAddress.PostalCode,
                        State         = foundAddress.AdminDistrict,

                        County = foundAddress.District,

                        Latitude  = (foundLocation == null) ? 0.0 : foundLocation.Latitude,
                        Longitude = (foundLocation == null) ? 0.0 : foundLocation.Longitude,
                    };
                }
            }

            return(location);
        }
コード例 #43
0
    private String GeocodeAddress(string address)
    {
        string results = "";
        string key = "ArLeGdHOcc5h7j3L4W37oFGcU9E-LF3tAZi4o0DfhXbPJ8aiyTGbIDNHex08R2u7";
        GeocodeRequest geocodeRequest = new GeocodeRequest();

        // Set the credentials using a valid Bing Maps key
        geocodeRequest.Credentials = new GeocodeService.Credentials();
        geocodeRequest.Credentials.ApplicationId = key;

        // Set the full address query
        geocodeRequest.Query = address;

        // Set the options to only return high confidence results
        ConfidenceFilter[] filters = new ConfidenceFilter[1];
        filters[0] = new ConfidenceFilter();
        filters[0].MinimumConfidence = GeocodeService.Confidence.High;

        // Add the filters to the options
        GeocodeOptions geocodeOptions = new GeocodeOptions();
        geocodeOptions.Filters = filters;
        geocodeRequest.Options = geocodeOptions;

        // Make the geocode request
        GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
        GeocodeResponse geocodeResponse = geocodeService.Geocode(geocodeRequest);

        if (geocodeResponse.Results.Length > 0)
            results = String.Format("Latitude: {0}\nLongitude: {1}",
              geocodeResponse.Results[0].Locations[0].Latitude,
              geocodeResponse.Results[0].Locations[0].Longitude);
        else
            results = "No Results Found";

        return results;
    }