示例#1
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);
        }
示例#2
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;
        }