Exemplo n.º 1
0
        public void OnSearChStringCompleted(object sender, SearchStringCompletedEventArgs e)
        {

        }
Exemplo n.º 2
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);
        }