Exemplo n.º 1
0
        public void LocationForAddress(string addressString, GeoCoordinate searchNearLocation, object callerState)
        {
            GeocodeRequest request = new GeocodeRequest();

            request.Credentials = new dev.virtualearth.net.webservices.v1.common.Credentials()
            {
                ApplicationId = bingMapsApiKey
            };
            request.Query       = addressString;
            request.UserProfile = new UserProfile()
            {
                CurrentLocation = new UserLocation()
                {
                    Latitude  = searchNearLocation.Latitude,
                    Longitude = searchNearLocation.Longitude
                },
                DistanceUnit = DistanceUnit.Mile,
                DeviceType   = DeviceType.Mobile,
                ScreenSize   = new SizeOfint()
                {
                    Width  = 480,
                    Height = 700
                }
            };

            GeocodeState state = new GeocodeState()
            {
                Query = addressString,
                SearchNearLocation = searchNearLocation,
                CallerState        = callerState
            };

            geocodeService.GeocodeAsync(request, state);
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
0
        private void set(string address)
        {
            UsingBingMaps.ServiceReference1.GeocodeRequest request = new UsingBingMaps.ServiceReference1.GeocodeRequest();

            // Only accept results with high confidence.
            request.Options = new GeocodeOptions()
            {
                Filters = new ObservableCollection <FilterBase>
                {
                    new ConfidenceFilter()
                    {
                        MinimumConfidence = Confidence.High
                    }
                }
            };

            request.Credentials = new Credentials()
            {
                ApplicationId = "ApSTxL8vPW3LwzcfWL1rgKGvLpm4Kmt5_pPrWQfbnU7BqpLDke69cWNWUkqjEVcz"
            };

            request.Query = address;

            // Make asynchronous call to fetch the geo coordinate data.
            _svc.GeocodeAsync(request);
        }
Exemplo n.º 5
0
        private void btnPlot_Click(object sender, RoutedEventArgs e)
        {
            BingMapGeoCodeService.GeocodeRequest request = new BingMapGeoCodeService.GeocodeRequest();

            // Only accept results with high confidence.
            request.Options = new GeocodeOptions()
            {
                Filters = new ObservableCollection <FilterBase>
                {
                    new ConfidenceFilter()
                    {
                        MinimumConfidence = Confidence.High
                    }
                }
            };


            request.Credentials = new Credentials()
            {
                ApplicationId = "AlWWYPw-HBVuA3AvU5AKn0cbGNp7jqjX0Vk5KFCIUHGgJRSktD0PRomkCnDPntPB"
            };

            request.Query = txtAddress.Text;

            // Make asynchronous call to fetch the geo coordinate data.
            _svc.GeocodeAsync(request);
        }
Exemplo n.º 6
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 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));
        }
Exemplo n.º 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);
        }
        /// <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);
                        }
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
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);
            }
        }
Exemplo n.º 12
0
        private void TextBoxAddLocation_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
        {
            string query = (sender as TextBox).Text;

            if (query.Length > 3)
            {
                GeocodeRequest request = new GeocodeRequest();
                request.Credentials =
                    new Credentials()
                {
                    ApplicationId = "Arz9raeGhoGWF5U5hv0Py-wnLL1ZMa82OF5BrFlSKExWfHzhlOaQ8gwBJldxi3Hg",
                };
                request.Query = query;

                geoCodeClient.GeocodeAsync(request);
            }
            else
            {
            }
        }
Exemplo n.º 13
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);
        }
        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);
        }
Exemplo n.º 15
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);
        }
        private void GeocodeAddress(string address, RoutingState state)
        {
            var request = new GeocodeRequest()
            {
                Culture = CultureInfo.CurrentUICulture.Name,
                Query   = address,

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

                // Only accept results with high confidence.
                Options = new GeocodeOptions()
                {
                    Filters = new ObservableCollection <FilterBase>
                    {
                        new ConfidenceFilter()
                        {
                            MinimumConfidence = UsingBingMaps.Bing.Geocode.Confidence.High
                        }
                    }
                }
            };

            // Get credentials and only then place an async call on the geocode service.
            _credentialsProvider.GetCredentials(credentials =>
            {
                // Pass in credentials for web services call.
                // Replace with your own Credentials.
                request.Credentials = credentials;

                // Make asynchronous call to fetch the data.
                _geocodeClient.GeocodeAsync(request, state);
            });
        }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
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);

       }
Exemplo n.º 19
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)
 {
     GeocodeRequest request = new GeocodeRequest() { Credentials = new Credentials { ApplicationId = BingMapCredential.CREDENTIAL } };
     request.Query = address;
     GeocodeServiceClient service = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
     service.GeocodeCompleted += (o, e) =>
     {
         if (e.Result != null && e.Result.Results.Any(obj => obj.Locations != null && obj.Locations.Any()))
         {
             double la = e.Result.Results.FirstOrDefault().Locations.FirstOrDefault().Latitude;
             double lon = e.Result.Results.FirstOrDefault().Locations.FirstOrDefault().Longitude;
             LocationChecked(this, new LocationCheckedEventArgs());
         }
         else
         {
             LocationChecked(this, new LocationCheckedEventArgs());
         }
     };
     service.GeocodeAsync(request);
 }
Exemplo n.º 20
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);
        }
Exemplo n.º 21
0
        public void GeoSearch(string keywords, Map mapView)
        {
            UriBuilder serviceUri = new UriBuilder("http://dev.virtualearth.net/webservices/v1/GeocodeService/GeocodeService.svc");
            BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None);
            binding.MaxReceivedMessageSize = int.MaxValue;
            binding.MaxBufferSize = int.MaxValue;

            GeocodeServiceClient geoSearchClient = new GeocodeServiceClient(binding, new EndpointAddress(serviceUri.Uri));
            GeocodeRequest req = new GeocodeRequest();
            req.Query = keywords;
            req.Credentials = new Credentials();
            req.Credentials.ApplicationId = ((App)Application.Current).GeoCodeServiceCredentials;

            req.ExecutionOptions = new ExecutionOptions();
            req.ExecutionOptions.SuppressFaults = true;

            LocationRect mapControlView = mapView.BoundingRectangle;
            LocationRect mapBounds = new LocationRect(mapControlView);

            req.Culture = mapView.Culture;
            req.UserProfile = new UserProfile();
            req.UserProfile.MapView = mapBounds;

            geoSearchClient.GeocodeCompleted += new EventHandler<GeocodeCompletedEventArgs>(geoSearchClient_GeocodeCompleted);
            geoSearchClient.GeocodeAsync(req);
        }
        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);
        }
        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;
        }
Exemplo n.º 24
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);
        }
Exemplo n.º 25
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);
        }