コード例 #1
0
ファイル: BingRepository.cs プロジェクト: VijayMVC/api
        public object UpdateBingAddressGeocode(Location location, string culture)
        {
            DbGeography result = null;

            var address = new Bing.Geocode.Address()
            {
                AddressLine   = location.Address1,
                AdminDistrict = location.ISOStateCode,
                CountryRegion = location.ISOCountryCode,
                Locality      = location.City,
                PostalCode    = location.PostalCode
            };

            var bingAppId = GetBingAppId();

            var geocodeRequest = new Bing.Geocode.GeocodeRequest()
            {
                Address     = address,
                Credentials = new Bing.Geocode.Credentials()
                {
                    ApplicationId = bingAppId
                },
                Culture = FormatCulture(culture),
                Options = new Bing.Geocode.GeocodeOptions()
                {
                    Count   = 1,
                    Filters = new List <Bing.Geocode.FilterBase>()
                    {
                        new Bing.Geocode.ConfidenceFilter()
                        {
                            MinimumConfidence = Bing.Geocode.Confidence.Medium
                        }
                    }
                }
            };

            var geocodeServiceClient = new Bing.Geocode.GeocodeServiceClient("BasicHttpBinding_IGeocodeService");

            var geocodeResponse = geocodeServiceClient.Geocode(geocodeRequest);

            if (geocodeResponse != null && geocodeResponse.Results != null && geocodeResponse.Results.Any())
            {
                var geocodeResult = geocodeResponse.Results.FirstOrDefault();

                if (geocodeResult != null)
                {
                    var geocodeLocation = geocodeResult.Locations.FirstOrDefault();

                    if (geocodeLocation != null && geocodeLocation.Latitude != 0 && geocodeLocation.Longitude != 0)
                    {
                        result = GeographyUtils.GetPointFromLatitudeAndLongitude(( float )geocodeLocation.Latitude,
                                                                                 ( float )geocodeLocation.Longitude);
                    }
                }
            }
            location.Latitude  = ( float )(result != null ? result.Latitude ?? 0 : 0);
            location.Longitude = ( float )(result != null ? result.Longitude ?? 0 : 0);
            return(location);
        }
コード例 #2
0
ファイル: BingRepository.cs プロジェクト: VijayMVC/api
        public DbGeography GetBingAddressGeocode(string address1, string city, string state, string postalCode, string country, string culture)
        {
            DbGeography result = null;

            var address = new Bing.Geocode.Address()
            {
                AddressLine   = address1,
                AdminDistrict = state,
                CountryRegion = country,
                Locality      = city,
                PostalCode    = postalCode
            };
            var bingAppId = GetBingAppId();

            var geocodeRequest = new Bing.Geocode.GeocodeRequest()
            {
                Address     = address,
                Credentials = new Bing.Geocode.Credentials()
                {
                    ApplicationId = bingAppId
                },
                Culture = FormatCulture(culture),
                Options = new Bing.Geocode.GeocodeOptions()
                {
                    Count   = 1,
                    Filters = new List <Bing.Geocode.FilterBase>()
                    {
                        new Bing.Geocode.ConfidenceFilter()
                        {
                            MinimumConfidence = Bing.Geocode.Confidence.Medium
                        }
                    }
                }
            };

            Bing.Geocode.GeocodeServiceClient geocodeServiceClient = new Bing.Geocode.GeocodeServiceClient("BasicHttpBinding_IGeocodeService");

            var geocodeResponse = geocodeServiceClient.Geocode(geocodeRequest);

            if (geocodeResponse != null && geocodeResponse.Results != null && geocodeResponse.Results.Count() > 0)
            {
                var geocodeResult = geocodeResponse.Results.FirstOrDefault();

                if (geocodeResult != null)
                {
                    var geocodeLocation = geocodeResult.Locations.FirstOrDefault();

                    if (geocodeLocation != null && geocodeLocation.Latitude != 0 && geocodeLocation.Longitude != 0)
                    {
                        result = GeographyUtils.GetPointFromLatitudeAndLongitude(( float )geocodeLocation.Latitude,
                                                                                 ( float )geocodeLocation.Longitude);
                    }
                }
            }

            return(result);
        }