Ejemplo n.º 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);
            }
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
    private string ReverseGeocodePoint(string locationString)
    {
        string results = "";
        string key     = "ArLeGdHOcc5h7j3L4W37oFGcU9E-LF3tAZi4o0DfhXbPJ8aiyTGbIDNHex08R2u7";
        ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest();

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

        // Set the point to use to find a matching address
        GeocodeService.Location point = new GeocodeService.Location();
        string[] digits = locationString.Split(',');

        point.Latitude  = double.Parse(digits[0].Trim());
        point.Longitude = double.Parse(digits[1].Trim());

        reverseGeocodeRequest.Location = point;

        // Make the reverse geocode request
        GeocodeServiceClient geocodeService  = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
        GeocodeResponse      geocodeResponse = geocodeService.ReverseGeocode(reverseGeocodeRequest);

        if (geocodeResponse.Results.Length > 0)
        {
            results = geocodeResponse.Results[0].DisplayName;
        }
        else
        {
            results = "No Results found";
        }

        return(results);
    }
        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);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Makes the reverse geocode request.
        /// </summary>
        /// <param name="l">The l.</param>
        private void MakeReverseGeocodeRequest(Location l)
        {
            try {
                // Set a Bing Maps key before making a request
                const string KEY = "AkRhgqPR6aujo-xib-KiR8Lt20wsn89GY4R9SP0RA6h4w7QT9mS3kKwYKKxjklfV";

                // Set the credentials using a valid Bing Maps key
                // Set the point to use to find a matching address
                var reverseGeocodeRequest = new ReverseGeocodeRequest {
                    Credentials = new Credentials {
                        ApplicationId = KEY
                    }
                };

                Location point = l;

                reverseGeocodeRequest.Location    = point;
                reverseGeocodeRequest.UserProfile = new UserProfile {
                    DeviceType = DeviceType.Mobile
                };

                // Make the reverse geocode request
                var geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
                geocodeService.ReverseGeocodeCompleted += lookupAddress_ReverseGeocodeCompleted;
                geocodeService.ReverseGeocodeAsync(reverseGeocodeRequest);
            } catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 6
0
        public Location GeocodeAddress(string address)
        {
            address = "Av. Brigadeiro Faria Lima, 2170 São José dos Campos SP 12227-000";
            var bingMapApiKey = ConfigurationManager.AppSettings["BingMapCredentials"];
            if (!string.IsNullOrEmpty(bingMapApiKey))
            {
                var geocodeRequest = new GeocodeRequest
                    { Credentials = new Credentials { ApplicationId = bingMapApiKey }, Query = address };

                // Set the options to only return high confidence results
                //var filters = new ConfidenceFilter[1];
                //filters[0] = new ConfidenceFilter { MinimumConfidence = Confidence.High };
                //var geocodeOptions = new GeocodeOptions { Filters = filters };
                //geocodeRequest.Options = geocodeOptions;

                // Make the geocode request
                var binding = new BasicHttpBinding();
                var endpointAddress =
                    new EndpointAddress(
                        "http://dev.virtualearth.net/webservices/v1/geocodeservice/GeocodeService.svc?wsdl");

                //var geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
                var geocodeService = new GeocodeServiceClient(binding, endpointAddress);
                var geocodeResponse = geocodeService.Geocode(geocodeRequest);

                if (geocodeResponse.Results.Length > 0)
                {
                    if (geocodeResponse.Results[0].Locations.Length > 0)
                    {
                        return geocodeResponse.Results[0].Locations[0];
                    }
                }
            }
            return null;
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="point"></param>
        /// <returns></returns>
        private async Task <string> ReverseGeocodePoint(Location point)
        {
            ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest();



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


            // Set the point to use to find a matching address
            reverseGeocodeRequest.Location = point;
            reverseGeocodeRequest.Culture  = "fr-FR";

            // Make the reverse geocode request
            GeocodeServiceClient geocodeService = new GeocodeServiceClient(GeocodeServiceClient.EndpointConfiguration.BasicHttpBinding_IGeocodeService);

            GeocodeService.GeocodeResponse geocodeResponse = await geocodeService.ReverseGeocodeAsync(reverseGeocodeRequest);

            string Results = geocodeResponse.Results[0].DisplayName;//*/



            return(Results);
        }
        private async Task <GeocodeResult> GeocodeAddress(string address)
        {
            GeocodeResult result = null;

            using (GeocodeServiceClient client = new GeocodeServiceClient("CustomBinding_IGeocodeService"))
            {
                GeocodeRequest request = new GeocodeRequest();
                request.Credentials = new Credentials()
                {
                    ApplicationId = Resources.BingApiKey
                };
                request.Query = address;

                try
                {
                    result = client.Geocode(request).Results[0];
                }
                catch (Exception)
                {
                    await this.interactionService.ShowMessageBox("Sorry", $"Could not find: {this.From}");
                }
            }

            return(result);
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
 private LocationModel()
 {
     geocodeService = new GeocodeServiceClient(
         new BasicHttpBinding(),
         new System.ServiceModel.EndpointAddress("http://dev.virtualearth.net/webservices/v1/geocodeservice/GeocodeService.svc")
         );
     geocodeService.GeocodeCompleted += new EventHandler <GeocodeCompletedEventArgs>(geocodeService_GeocodeCompleted);
 }
 private LocationModel()
 {
     geocodeService = new GeocodeServiceClient(
         new BasicHttpBinding(),
         new System.ServiceModel.EndpointAddress("http://dev.virtualearth.net/webservices/v1/geocodeservice/GeocodeService.svc")
         );
     geocodeService.GeocodeCompleted += new EventHandler<GeocodeCompletedEventArgs>(geocodeService_GeocodeCompleted);
 }
Ejemplo n.º 12
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            this.ContentPanel.DataContext = States.CurReport;
            switch (States.CurReport.Mood)
            {
                case ("positive"):
                    MoodText.Text = "Happy";
                    break;
                case "negative":
                    MoodText.Text = "Unhappy";
                    break;
                case "concerned":
                    MoodText.Text = "Concerned";
                    break;
            }

            if (!(States.CurReport.Photo == "" || States.CurReport.Photo == null))
            {
                this.PhotoHeader.Visibility = Visibility.Visible;
                this.PhotoContainer.Visibility = Visibility.Visible;
            }

            if (States.CurReport.Location == "" || States.CurReport.Location == "Null")
            {
                this.LocationBox.Text = "No Location Provided";
            }
            else
            {
                GeoCoordinate location = new GeoCoordinate();
                string[] coordinate = States.CurReport.Location.Split((','));
                location.Latitude = Convert.ToDouble(coordinate[0]);
                location.Longitude = Convert.ToDouble(coordinate[1]);

                ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest();

                // Set the credentials using a valid Bing Maps key
                reverseGeocodeRequest.Credentials = new Credentials();
                reverseGeocodeRequest.Credentials.ApplicationId =
                    "ApIZ31eaMUXWc4YVuYaZZSi7LdLjbtdfHWcv7n-ax0z1-ytR8z9GbRxAVyLCJFC5";

                // Set the point to use to find a matching address
                //BingMaps.Location point = new BingMaps.Location();
                //point.Latitude = location.Latitude;
                //point.Longitude = location.Longitude;
                reverseGeocodeRequest.Location = new Location();
                reverseGeocodeRequest.Location.Latitude = location.Latitude;
                reverseGeocodeRequest.Location.Longitude = location.Longitude;

                // Make the reverse geocode request
                GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
                geocodeService.ReverseGeocodeCompleted +=
                    new EventHandler<ReverseGeocodeCompletedEventArgs>(geocodeService_ReverseGeocodeCompleted);
                geocodeService.ReverseGeocodeAsync(reverseGeocodeRequest);
            }
        }
 public void TestFindAddressCandidates()
 {
     var serviceClient = new GeocodeServiceClient();
     var inputFields = new Dictionary<string, string>();
     inputFields.Add(@"SingleLine", @"Cologne");
     var outputNames = new List<string>();
     outputNames.Add(@"Name");
     var candidates = serviceClient.FindAddressCandidates(inputFields, outputNames);
     Assert.IsNotNull(candidates, @"The candidates must not be null!");
 }
Ejemplo n.º 14
0
        public VendorGeoLocation GetVendorAddress(int VendorID)
        {
            AdventureWorksEntities entities = new AdventureWorksEntities();
            var vendorAddress = from va in entities.VendorAddresses
                                join
                                a in entities.Addresses
                                on va.AddressID equals a.AddressID
                                select a;

            model.Address address = vendorAddress.First <model.Address>();

            GeocodeServiceClient geoClient = new GeocodeServiceClient();
            GeocodeRequest       request   = new GeocodeRequest();

            request.Address = new BingMapsGeoCodeSvc.Address()
            {
                AddressLine = address.AddressLine1,
                PostalCode  = address.PostalCode,
                PostalTown  = address.City,
            };
            //Credentials to your AppID from the Bing Maps portal
            request.Credentials = new Credentials()
            {
                ApplicationId =
                    "AhZkLXRfdSEi_XRkUKCmjBaDsIvZf2baS-9jYy1HGPaGqJErHONhnk80jJdlmOLj"
            };
            //Set filter to high confidence
            request.Options = new GeocodeOptions()
            {
                Filters = new FilterBase[]
                {
                    new ConfidenceFilter()
                    {
                        MinimumConfidence = Confidence.High
                    }
                }
            };
            GeocodeResponse response = geoClient.Geocode(request);
            //Get the highest confidence result
            var vendorGeoLoc = (from r in response.Results

                                orderby(int) r.Confidence ascending

                                select r).FirstOrDefault();

            //take vendor address and look it up on Bing
            VendorGeoLocation location = new VendorGeoLocation()
            {
                Latitude  = vendorGeoLoc.Locations[0].Latitude,
                Longitude = vendorGeoLoc.Locations[0].Longitude
            };

            return(location);
        }
Ejemplo n.º 15
0
        private void Geocode(string name, int id)
        {
            GeocodeServiceClient client  = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
            GeocodeRequest       request = new GeocodeRequest();

            request.Credentials = new Credentials();
            request.Credentials.ApplicationId = "AjlmpILfXZMz8HCz-aqkBfnZZt6UXFnVqXVIP7glejUCYrliehYU6xtEBZVshDZM";
            request.Query            = name;
            client.GeocodeCompleted += new EventHandler <GeocodeCompletedEventArgs>(client_GeocodeCompleted);
            client.GeocodeAsync(request, id);
        }
        public void TestFindAddressCandidates()
        {
            var serviceClient = new GeocodeServiceClient();
            var inputFields   = new Dictionary <string, string>();

            inputFields.Add(@"SingleLine", @"Cologne");
            var outputNames = new List <string>();

            outputNames.Add(@"Name");
            var candidates = serviceClient.FindAddressCandidates(inputFields, outputNames);

            Assert.IsNotNull(candidates, @"The candidates must not be null!");
        }
Ejemplo n.º 17
0
        public static void ReverseGeocodeAddress(Dispatcher uiDispatcher, CredentialsProvider credentialsProvider, Location location, Action <GeocodeResult> completed = null, Action <GeocodeError> error = null)
        {
            completed = completed ?? (r => { });
            error     = error ?? (e => { });

            // Get credentials and only then place an async call on the geocode service.
            credentialsProvider.GetCredentials(credentials =>
            {
                var request = new ReverseGeocodeRequest()
                {
                    // Pass in credentials for web services call.
                    Credentials = credentials,

                    Culture  = CultureInfo.CurrentUICulture.Name,
                    Location = location,

                    // Don't raise exceptions.
                    ExecutionOptions = new ExecutionOptions
                    {
                        SuppressFaults = true
                    },
                };

                EventHandler <ReverseGeocodeCompletedEventArgs> reverseGeocodeCompleted = (s, e) =>
                {
                    try
                    {
                        if (e.Result.ResponseSummary.StatusCode != Bing.Geocode.ResponseStatusCode.Success ||
                            e.Result.Results.Count == 0)
                        {
                            // Report geocode error.
                            uiDispatcher.BeginInvoke(() => error(new GeocodeError(e)));
                        }
                        else
                        {
                            // Only report on first result.
                            var firstResult = e.Result.Results.First();
                            uiDispatcher.BeginInvoke(() => completed(firstResult));
                        }
                    }
                    catch (Exception ex)
                    {
                        uiDispatcher.BeginInvoke(() => error(new GeocodeError(ex.Message, ex)));
                    }
                };

                var geocodeClient = new GeocodeServiceClient();
                geocodeClient.ReverseGeocodeCompleted += reverseGeocodeCompleted;
                geocodeClient.ReverseGeocodeAsync(request);
            });
        }
        public static Task <GeocodeResponse> GetGeocodeByAddress(string address)
        {
            GeocodeRequest request = new GeocodeRequest();

            request.Credentials = new Credentials();
            request.Credentials.ApplicationId = KEY;

            request.Query = address;

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

            return(geocodeService.GeocodeAsync(request));
        }
Ejemplo n.º 19
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);
            }
        }
Ejemplo n.º 20
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);
        }
Ejemplo n.º 21
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);
        }
Ejemplo n.º 22
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;
            }
            
        }
Ejemplo n.º 23
0
        public static GeocodeServiceClient GetGeocodeService(DependencyObject obj = null)
        {
            GeocodeServiceClient service = null;
            if (IsDesignMode(obj))
            {
                Binding binding = new BasicHttpBinding();
                EndpointAddress address = new EndpointAddress("http://dev.virtualearth.net/webservices/v1/geocodeservice/GeocodeService.svc");
                service = new GeocodeServiceClient(binding, address);
            }
            else
            {
                service = new GeocodeServiceClient("CustomBinding_IGeocodeService");
            }

            return service;
        }
Ejemplo n.º 24
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));
        }
Ejemplo n.º 25
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;
        }
Ejemplo n.º 26
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);
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Makes the geocode request.
        /// </summary>
        /// <param name="a">A.</param>
        public void MakeGeocodeRequest(Address a)
        {
            try {
                                // Set a Bing Maps key before making a request
                                const string KEY = "AkRhgqPR6aujo-xib-KiR8Lt20wsn89GY4R9SP0RA6h4w7QT9mS3kKwYKKxjklfV";

                                // Set the credentials using a valid Bing Maps key
                                // Set the point to use to find a matching address
                                var geocodeRequest = new GeocodeRequest { Credentials = new Credentials { ApplicationId = KEY }, Address = a, UserProfile = new UserProfile { DeviceType = DeviceType.Mobile } };

                                // Make the reverse geocode request
                                var geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
                                geocodeService.GeocodeCompleted += geocodeService_GeocodeCompleted;
                                geocodeService.GeocodeAsync(geocodeRequest);
                        } catch (Exception ex) {
                                MessageBox.Show(ex.Message);
                        }
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Verifie les coordonnées géographiques d'un rendez-vous du Calendrier
        /// </summary>
        /// <param name="appointment">Rendez-vous</param>
        /// <remarks>Abonnez vous d'abord à l'évènement LocationChecked avant l'appel de cette méthode</remarks>
        public void CheckLocationAsync(Appointment appointment)
        {
            //Procédure de connexion et préparation de la requete
            GeocodeRequest request = new GeocodeRequest() { Credentials = new Credentials { ApplicationId = BingMapCredential.CREDENTIAL } };
            if (appointment.Location == null)
                return;
            request.Query = appointment.Location;
            GeocodeServiceClient service = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");

            //Lorsque bing map nous envoie une réponse
            service.GeocodeCompleted += (o, e) =>
            {
                Appointment a = e.UserState as Appointment;
                LocationCheckedEventArgs eventToSend = new LocationCheckedEventArgs();
                //Construction du Meeting qui sera envoyé en résultat
                Meeting m = new Meeting();
                m.Subject = a.Subject;
                m.DateTime = a.StartTime;
                m.Duration = (a.EndTime - a.StartTime).TotalMinutes;
                m.Address = a.Location;

                m.IsLocationFail = true;
                //Si dans le service bing map a trouvé les latitude et longitude de la requete
                if (e.Result != null)
                {
                    if (e.Result.Results.Any(obj => obj.Locations != null && obj.Locations.Any()) && e.Result.Results.Count > 0)
                    {
                        if (e.Result.Results.FirstOrDefault().Confidence == Confidence.High && !String.IsNullOrEmpty(e.Result.Results.FirstOrDefault().Address.Locality))
                        {
                            m.IsLocationFail = false;
                            m.Location.Latitude = e.Result.Results.FirstOrDefault().Locations.FirstOrDefault().Latitude;
                            m.Location.Longitude = e.Result.Results.FirstOrDefault().Locations.FirstOrDefault().Longitude;
                            m.City = e.Result.Results.FirstOrDefault().Address.Locality;
                        }
                    }

                }

                eventToSend.Meeting = m;
                //On notifie l'observateur (dans ce cas, la méthode GetAllMeetingsAsync)
                LocationChecked(this, eventToSend);
            };
            service.GeocodeAsync(request, appointment);
        }
        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;
        }
        public RouteCalculator(
            CredentialsProvider credentialsProvider,
            string to,
            string from,
            Dispatcher uiDispatcher,
            Action <RouteResponse> routeFound)
        {
            if (credentialsProvider == null)
            {
                throw new ArgumentNullException("credentialsProvider");
            }

            if (string.IsNullOrEmpty(to))
            {
                throw new ArgumentNullException("to");
            }

            if (string.IsNullOrEmpty(from))
            {
                throw new ArgumentNullException("from");
            }

            if (uiDispatcher == null)
            {
                throw new ArgumentNullException("uiDispatcher");
            }

            if (routeFound == null)
            {
                throw new ArgumentNullException("routeFound");
            }

            _credentialsProvider = credentialsProvider;
            _to           = to;
            _from         = from;
            _uiDispatcher = uiDispatcher;
            _routeFound   = routeFound;

            _geocodeClient = new GeocodeServiceClient();
            _geocodeClient.GeocodeCompleted += client_GeocodeCompleted;

            _routeClient = new RouteServiceClient();
            _routeClient.CalculateRouteCompleted += client_RouteCompleted;
        }
Ejemplo n.º 31
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);
        }
Ejemplo n.º 32
0
        public void Find(string location, EventHandler onResults)
        {
            if (IsInitialized)
            {
                var geocodeRequest = new GeocodeRequest
                                         {
                                             Credentials = new Credentials {Token = token},
                                             Query = location
                                         };

                var geocodeService = new GeocodeServiceClient();
                geocodeService.GeocodeCompleted += (o, e) =>
                                                       {
                                                           GeocodeResponse geocodeResponse = e.Result;
                                                           onResults(this, new GeocodeResultArgs {Results = geocodeResponse.Results});
                                                       };
                geocodeService.GeocodeAsync(geocodeRequest);
            }
        }
        private void geocode_Click(object sender, EventArgs e)
        {
            GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
            geocodeService.ReverseGeocodeCompleted += geocodeService_ReverseGeocodeCompleted;

            ReverseGeocodeRequest geocodeRequest = new ReverseGeocodeRequest()
            {
                Credentials = new Credentials
                {
                    ApplicationId = "enter your developer key here"
                },
                Location = new GeocodeLocation
                {
                    Latitude = previous.Latitude,
                    Longitude = previous.Longitude,
                }
            };
            geocodeService.ReverseGeocodeAsync(geocodeRequest);
        }
Ejemplo n.º 34
0
        private string ReverseGeocodePoint(string locationString)
        {
            string results = "";
            string key     = "Am_qwaGQRh4tOT1wCX_lWd2EzqKl1_PuXjX9nuMQZFWehKYgcXqT99avIJhvAGmx";
            ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest();

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

            // Set the point to use to find a matching address
            GeocodeService.Location point = new GeocodeService.Location();
            string[] digits = locationString.Split(',');

            if (digits.Length == 2 &&
                digits[0].Length > 0 && digits[1].Length > 0)
            {
                point.Latitude  = double.Parse(digits[0].Trim());
                point.Longitude = double.Parse(digits[1].Trim());

                reverseGeocodeRequest.Location = point;

                // Make the reverse geocode request
                GeocodeServiceClient geocodeService  = new GeocodeServiceClient();
                GeocodeResponse      geocodeResponse = geocodeService.ReverseGeocode(reverseGeocodeRequest);

                if (geocodeResponse.Results.Length > 0)
                {
                    results = geocodeResponse.Results[0].DisplayName;
                }
                else
                {
                    results = "Location data not available";
                }

                return(results);
            }
            else
            {
                return("Location data not available");
            }
        }
Ejemplo n.º 35
0
        public void Find(Point location, EventHandler onResults)
        {
            if (IsInitialized)
            {
                var reverseGeocodeRequest = new ReverseGeocodeRequest
                                                {
                                                    Credentials = new Credentials {Token = token},
                                                    Location = new Location {Longitude = location.X, Latitude = location.Y}
                                                };

                var geocodeService = new GeocodeServiceClient();

                geocodeService.ReverseGeocodeCompleted += (o, e) =>
                                                              {
                                                                  GeocodeResponse geocodeResponse = e.Result;
                                                                  onResults(this, new GeocodeResultArgs {Results = geocodeResponse.Results});
                                                              };
                geocodeService.ReverseGeocodeAsync(reverseGeocodeRequest);
            }
        }
Ejemplo n.º 36
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);
    }
Ejemplo n.º 37
0
        /// <summary>
        /// Verifie les coordonnées géographiques d'un rendez-vous du Calendrier
        /// </summary>
        /// <param name="appointment">Rendez-vous</param>
        /// <remarks>Abonnez vous d'abord à l'évènement LocationChecked avant l'appel de cette méthode</remarks>
        public void CheckLocationAsync(Appointment appointment)
        {
            //Procédure de connexion et préparation de la requete
            GeocodeRequest request = new GeocodeRequest() { Credentials = new Credentials { ApplicationId = BingMapCredential.CREDENTIAL } };
            if (appointment.Location == null)
                return;
            request.Query = appointment.Location;
            GeocodeServiceClient service = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
            
            //Lorsque bing map nous envoie une réponse
            service.GeocodeCompleted += (o, e) =>
            {
                //Construction du Meeting qui sera envoyé en résultat
                Meeting m = new Meeting();
                m.Subject = appointment.Subject;
                m.DateTime = appointment.StartTime;
                m.Duration = (appointment.EndTime - appointment.StartTime).TotalMinutes;

                //Si dans le service bing map a trouvé les latitude et longitude de la requete
                if (e.Result == null || 
                    e.Result.Results.Count < 0 || 
                    e.Result.Results.Any(obj => obj.Locations == null && obj.Locations.Any()))
                {
                    throw new Exception("Pas de géolocalisation possible");
                }

                m.IsLocationFail = true;
                if (e.Result.Results.FirstOrDefault().Confidence == Confidence.High)
                {
                    m.IsLocationFail = false;
                    m.Location.Latitude = e.Result.Results.FirstOrDefault().Locations.FirstOrDefault().Latitude;
                    m.Location.Longitude = e.Result.Results.FirstOrDefault().Locations.FirstOrDefault().Longitude;
                }

                LocationCheckedEventArgs eventToSend = new LocationCheckedEventArgs();
                eventToSend.Meeting = m;
                //On notifie l'observateur (dans ce cas, la méthode GetAllMeetingsAsync)
                LocationChecked(this, eventToSend);
            };
            service.GeocodeAsync(request);
        }
Ejemplo n.º 38
0
        //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);
        }
        private void geocode_Click(object sender, EventArgs e)
        {
            GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");

            geocodeService.ReverseGeocodeCompleted += geocodeService_ReverseGeocodeCompleted;

            ReverseGeocodeRequest geocodeRequest = new ReverseGeocodeRequest()
            {
                Credentials = new Credentials
                {
                    ApplicationId = "enter your developer key here"
                },
                Location = new GeocodeLocation
                {
                    Latitude  = previous.Latitude,
                    Longitude = previous.Longitude,
                }
            };

            geocodeService.ReverseGeocodeAsync(geocodeRequest);
        }
Ejemplo n.º 40
0
        public bool QueryLocation(string queryString, out double lat, out double lng)
        {
            lat = 0;
            lng = 0;

            GeocodeRequest geocodeRequest = new GeocodeRequest();
            geocodeRequest.Query = queryString;
            geocodeRequest.Options = new GeocodeOptions() { Filters = new FilterBase[] { new ConfidenceFilter() { MinimumConfidence = Confidence.High } }, Count = 1 };
            geocodeRequest.Credentials = creds;

            GeocodeServiceClient geocodeServiceClient = new GeocodeServiceClient("CustomBinding_IGeocodeService");
            GeocodeResponse geocodeResponse = geocodeServiceClient.Geocode(geocodeRequest);

            bool locationFound = geocodeResponse.Results.Count() > 0;
            if (locationFound)
            {
                lat = geocodeResponse.Results[0].Locations[0].Latitude;
                lng = geocodeResponse.Results[0].Locations[0].Longitude;
            }
            return locationFound;
        }
Ejemplo n.º 41
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";
            }
        }
        public AddressPlotting()
        {
            InitializeComponent();

            _svc = new GeocodeServiceClient();
            _svc.GeocodeCompleted += (s, e) =>
            {
                // sort the returned record by ascending confidence in order for
                // highest confidence to be on the top. Based on the numeration High value is
                // at 0, Medium value at 1 and Low volue at 2
                var geoResult = (from r in e.Result.Results
                                 orderby (int)r.Confidence ascending
                                 select r).FirstOrDefault();
                if (geoResult != null)
                {
                    this.SetLocation(geoResult.Locations[0].Latitude,
                        geoResult.Locations[0].Longitude,
                        10,
                        true);
                }
            };
        }
Ejemplo n.º 43
0
        public AddressPlotting()
        {
            InitializeComponent();

            _svc = new GeocodeServiceClient();
            _svc.GeocodeCompleted += (s, e) =>
            {
                // sort the returned record by ascending confidence in order for
                // highest confidence to be on the top. Based on the numeration High value is
                // at 0, Medium value at 1 and Low volue at 2
                var geoResult = (from r in e.Result.Results
                                 orderby(int) r.Confidence ascending
                                 select r).FirstOrDefault();
                if (geoResult != null)
                {
                    this.SetLocation(geoResult.Locations[0].Latitude,
                                     geoResult.Locations[0].Longitude,
                                     10,
                                     true);
                }
            };
        }
        private async Task <Bing.Maps.Location> GeocodePlaceName(string place)
        {
            Bing.Maps.Location geocodedPlace = new Bing.Maps.Location();

            GeocodeRequest geocodeRequest = new GeocodeRequest();

            geocodeRequest.Credentials = new Credentials();
            geocodeRequest.Credentials.ApplicationId = BING_MAPS_KEY;

            geocodeRequest.Query = place;
            GeocodeServiceClient geocodeService = new GeocodeServiceClient(
                GeocodeServiceClient.EndpointConfiguration.BasicHttpBinding_IGeocodeService);
            GeocodeResponse geocodeResponse = await geocodeService.GeocodeAsync(geocodeRequest);

            if (geocodeResponse.Results.Count > 0)
            {
                geocodedPlace.Latitude  = geocodeResponse.Results[0].Locations[0].Latitude;
                geocodedPlace.Longitude = geocodeResponse.Results[0].Locations[0].Longitude;
            }

            return(geocodedPlace);
        }
Ejemplo n.º 45
0
        async public Task <String> ReverseGeocodePoint(Bing.Maps.Location l)
        {
            //return await ReverseGeocodeGoogle(l.Longitude, l.Latitude);

            string key = "AqzQTQg1GrHIoL2a5Ycf08czzcxAooMpXiADdOgZQYPBtwpuSSf8Fd4y7MUTJo-h";
            ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest();

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

            // Set the point to use to find a matching address
            geocodeservice.Location point = new geocodeservice.Location();

            point.Latitude  = l.Latitude;
            point.Longitude = l.Longitude;

            reverseGeocodeRequest.Location = point;

            // Make the reverse geocode request
            GeocodeServiceClient geocodeService = new GeocodeServiceClient(geocodeservice.GeocodeServiceClient.EndpointConfiguration.BasicHttpBinding_IGeocodeService);

            // sometimes reverseGeocode is not getting me the right location so we will try to call the service a couple of times until it works, after a bit of tryouts we just return an error.
            int             numberOfTries   = 10;
            GeocodeResponse geocodeResponse = await geocodeService.ReverseGeocodeAsync(reverseGeocodeRequest);

            while (geocodeResponse.Results.Count == 0)
            {
                geocodeResponse = await geocodeService.ReverseGeocodeAsync(reverseGeocodeRequest);

                if (numberOfTries == 0)
                {
                    break;
                }
                numberOfTries--;
            }
            return(geocodeResponse.Results[0].Address.Locality);
        }
Ejemplo n.º 46
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);
        }
Ejemplo n.º 47
0
        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 = "******";
        }
Ejemplo n.º 48
0
        public string GeocodeReverseLookup(string latLong)
        {
            var bingMapApiKey = ConfigurationManager.AppSettings["BingMapCredentials"];
            var point = new Location();
            var latLongValue = latLong.Split(',');
            point.Latitude = double.Parse(latLongValue[0].Trim());
            point.Longitude = double.Parse(latLongValue[1].Trim());

            var reverseGeocodeRequest = new ReverseGeocodeRequest
                {
                    Credentials = new Credentials { ApplicationId = bingMapApiKey },
                    Location = point
                };

            var geocodeService = new GeocodeServiceClient();
            var geocodeResponse = geocodeService.ReverseGeocode(reverseGeocodeRequest);

            if(geocodeResponse.Results.Length > 0)
            {
                    return geocodeResponse.Results[0].DisplayName;
            }

            return null;
        }
        public static void ReverseGeocodeAddress(Dispatcher uiDispatcher, CredentialsProvider credentialsProvider, Location location, Action<GeocodeResult> completed = null, Action<GeocodeError> error = null)
        {
            completed = completed ?? (r => { });
            error = error ?? (e => { });

            // Get credentials and only then place an async call on the geocode service.
            credentialsProvider.GetCredentials(credentials =>
            {
                var request = new ReverseGeocodeRequest()
                {
                    // Pass in credentials for web services call.
                    Credentials = credentials,

                    Culture = CultureInfo.CurrentUICulture.Name,
                    Location = location,

                    // Don't raise exceptions.
                    ExecutionOptions = new UsingBingMaps.Bing.Geocode.ExecutionOptions
                    {
                        SuppressFaults = true
                    },
                };

 

                EventHandler<ReverseGeocodeCompletedEventArgs> reverseGeocodeCompleted = (s, e) =>
                {
                    try
                    {
                        if (e.Result.ResponseSummary.StatusCode != UsingBingMaps.Bing.Geocode.ResponseStatusCode.Success ||
                            e.Result.Results.Count == 0)
                        {
                            // Report geocode error.
                            uiDispatcher.BeginInvoke(() => error(new GeocodeError(e)));
                        }
                        else
                        {
                            // Only report on first result.
                            var firstResult = e.Result.Results.First();
                            uiDispatcher.BeginInvoke(() => completed(firstResult));
                            Debug.WriteLine("street=" + firstResult.Address.AddressLine.ToString());
                            Debug.WriteLine("admin district=" + firstResult.Address.AdminDistrict.ToString());
                            Debug.WriteLine("country region=" + firstResult.Address.CountryRegion.ToString());
                            Debug.WriteLine("district=" + firstResult.Address.District.ToString());
                            Debug.WriteLine("formatted addres=" + firstResult.Address.FormattedAddress.ToString());
                            Debug.WriteLine("locality=" + firstResult.Address.Locality.ToString());
                            Debug.WriteLine("postal code=" + firstResult.Address.PostalCode.ToString());
                            Debug.WriteLine("postal town=" + firstResult.Address.PostalTown.ToString());
                            CurrentAddress = firstResult.Address.FormattedAddress.ToString();
                            CurrentAddress_AdminDistrict = firstResult.Address.AdminDistrict.ToString();
                            CurrentAddress_CountryRegion = firstResult.Address.CountryRegion.ToString();
                            CurrentAddress_Locality = firstResult.Address.Locality.ToString();
                            CurrentAddress_PostalCode = firstResult.Address.PostalCode.ToString();
                            CurrentAddress_AddressLine = firstResult.Address.AddressLine.ToString();
                        }
                    }
                    catch (Exception ex)
                    {
                        uiDispatcher.BeginInvoke(() => error(new GeocodeError(ex.Message, ex)));
                    }
                };

                var geocodeClient = new GeocodeServiceClient();
                geocodeClient.ReverseGeocodeCompleted += reverseGeocodeCompleted;
                geocodeClient.ReverseGeocodeAsync(request);
            });
        }
Ejemplo n.º 50
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";
            }
        }
        private async Task<Bing.Maps.Location> GeocodePlaceName(string place)
        {
            Bing.Maps.Location geocodedPlace = new Bing.Maps.Location();
            
            GeocodeRequest geocodeRequest = new GeocodeRequest();
            geocodeRequest.Credentials = new Credentials();
            geocodeRequest.Credentials.ApplicationId = BING_MAPS_KEY;

            geocodeRequest.Query = place;
            GeocodeServiceClient geocodeService = new GeocodeServiceClient(
                GeocodeServiceClient.EndpointConfiguration.BasicHttpBinding_IGeocodeService);
            GeocodeResponse geocodeResponse = await geocodeService.GeocodeAsync(geocodeRequest);

            if (geocodeResponse.Results.Count > 0)
            {
                geocodedPlace.Latitude = geocodeResponse.Results[0].Locations[0].Latitude;
                geocodedPlace.Longitude = geocodeResponse.Results[0].Locations[0].Longitude;
            }

            return geocodedPlace;
        }
Ejemplo n.º 52
0
        private void reverseGeocode(GeoCoordinate location)
        {
            ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest();
            reverseGeocodeRequest.Credentials = new Credentials();
            string AppId = App.Current.Resources["BingApplicationId"] as string;
            reverseGeocodeRequest.Credentials.ApplicationId = AppId;
            reverseGeocodeRequest.Location = location;

            GeocodeServiceClient geocodeClient = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
            geocodeClient.ReverseGeocodeCompleted += geocodeClient_ReverseGeocodeCompleted;
            geocodeClient.ReverseGeocodeAsync(reverseGeocodeRequest);
        }
Ejemplo n.º 53
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;
            }
        }
Ejemplo n.º 54
0
        /// <summary>
        /// Cherche la latitude et la longitude d'une adresse sous forme de chaine de caractère
        /// </summary>
        /// <param name="address"></param>
        /// <remarks>Deprecated</remarks>
        public void SearchStringAsync(string address, object userData = null)
        {
            GeocodeRequest request = new GeocodeRequest() { Credentials = new Credentials { ApplicationId = BingMapCredential.CREDENTIAL } };
            request.Query = address;
            GeocodeServiceClient service = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
            service.GeocodeCompleted += (o, e) =>
            {
                var arg = new SearchStringCompletedEventArgs(new Location());
                arg.Error = true;
                arg.UserData = userData;
                if ((e.Result != null || e.Result.Results.Any(obj => obj.Locations != null && obj.Locations.Any())) && e.Result.Results.Count > 0)
                {

                    if (e.Result.Results.FirstOrDefault().Confidence == Confidence.High && !String.IsNullOrEmpty(e.Result.Results.FirstOrDefault().Address.Locality))
                    {
                        arg.Location = new Location()
                            {
                                Latitude = e.Result.Results.FirstOrDefault().Locations.FirstOrDefault().Latitude,
                                Longitude = e.Result.Results.FirstOrDefault().Locations.FirstOrDefault().Longitude
                            };
                        arg.Error = false;
                        arg.City = e.Result.Results.FirstOrDefault().Address.Locality;
                        arg.Address = e.Result.Results.FirstOrDefault().Address.FormattedAddress;
                    }
                }
                if(SearchStringCompleted != null)
                    SearchStringCompleted(this, arg);
            };
            service.GeocodeAsync(request);
        }
Ejemplo n.º 55
0
       private void Geocode(string name,int id)
       {
           GeocodeServiceClient client = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
           GeocodeRequest request = new GeocodeRequest();
           request.Credentials = new Credentials();
           request.Credentials.ApplicationId = "AjlmpILfXZMz8HCz-aqkBfnZZt6UXFnVqXVIP7glejUCYrliehYU6xtEBZVshDZM";
           request.Query = name;
           client.GeocodeCompleted += new EventHandler<GeocodeCompletedEventArgs>(client_GeocodeCompleted);
           client.GeocodeAsync(request);

       }
Ejemplo n.º 56
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;
        }
Ejemplo n.º 57
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);
            }
        }
Ejemplo n.º 58
0
        private void LoadLocations()
        {
            GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");

            GeocodeRequest geocodeRequest = new GeocodeRequest();
            {
                geocodeRequest.Credentials = new Credentials() { ApplicationId = "AmLt8xEVcOt7YnueGJfSuGU14Y8ednN6f8TMUPwd50GZMkvzluzkIKzQKAB92zO2" };
                geocodeRequest.Query = location;
                geocodeRequest.Options = new GeocodeOptions()
                {
                    Filters = new System.Collections.ObjectModel.ObservableCollection<FilterBase>()
                };

            };
            geocodeRequest.Options.Filters.Add(new ConfidenceFilter()
            {
                MinimumConfidence = Confidence.High
            });

            geocodeService.GeocodeAsync(geocodeRequest);
            geocodeService.GeocodeCompleted += (sender, e) => geoCode_GeocodeCompleted(sender, e);
        }
Ejemplo n.º 59
0
        public string ReverseGeocodePoint(string locationString)
        {
            string results = "";

            ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest();

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

            // Set the point to use to find a matching address
            GeocodeService.Location point = new GeocodeService.Location();
            string[] digits = locationString.Split(',');

            point.Latitude = double.Parse(digits[0].Trim());
            point.Longitude = double.Parse(digits[1].Trim());

            reverseGeocodeRequest.Location = point;

            // Make the reverse geocode request
            GeocodeServiceClient geocodeService = new GeocodeServiceClient();
            GeocodeResponse geocodeResponse = geocodeService.ReverseGeocode(reverseGeocodeRequest);

            if (geocodeResponse.Results.Length > 0)
                results = geocodeResponse.Results[0].DisplayName;
            else
                results = "No Results found";

            return results;
        }
Ejemplo n.º 60
0
        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;
        }