Geocodeservice of bingmap performs geographic location retrieval and reverse retrieval-Background implementation

Source: Internet
Author: User

1. Add a web service reference for geocodeservice

Geocodeservice is a Web Service released by the WCF technology, the map encoding Service provides a valid physical address to match the corresponding map address (both geographic longitude and latitude coordinates) on the map) the physical address path is reversely matched with geographic longitude and latitude coordinates. To use the service, you need to add a web service reference for the Service (http://dev.virtualearth.net/webservices/v1/geocodeservice/GeocodeService.svc), as shown in

2. Obtain the latitude and longitude code through the address:

<span style="font-size:14px;">GeocodeServiceClient geocodeService = new GeocodeServiceClient();GeocodeRequest geocodeRequest = new GeocodeRequest();geocodeRequest.Credentials = new Credentials();geocodeRequest.Credentials.ApplicationId = "Arn2694QD8zXQJGN_IgecLbotcSVT1gTyRFfNSdPsIOO - yWjkkZRbwKcNEpCfelq";geocodeRequest.Query = sAddress;ConfidenceFilter[] filters = new ConfidenceFilter[1];filters[0] = new ConfidenceFilter();filters[0].MinimumConfidence = Confidence.Low;GeocodeOptions geocodeOptions = new GeocodeOptions();geocodeOptions.Filters = filters;geocodeRequest.Options = geocodeOptions;GeocodeResponse geocodeResponse = new GeocodeResponse();geocodeResponse = geocodeService.Geocode(geocodeRequest);if (geocodeResponse.Results != null){int iLength = geocodeResponse.Results.Length;if (iLength >= 1){string sConfidence = geocodeResponse.Results[0].Confidence.ToString();if (sConfidence == "High"){string sState = geocodeResponse.Results[0].Address.AdminDistrict;string sCity = geocodeResponse.Results[0].Address.Locality;string sZip = geocodeResponse.Results[0].Address.PostalCode;string sLat = geocodeResponse.Results[0].Locations[0].Latitude.ToString();string sLon = geocodeResponse.Results[0].Locations[0].Longitude.ToString();string sqlExist = "select * from mapping_geodata_boundary where code='NJ0415' and boundary.STContains(geometry::STGeomFromText('POINT(" + sLon + " " + sLat + ")', 0))=1";DataTable dtExist = _dataAccess.GetTables(sqlExist);if (dtExist.Rows.Count > 0){//Updatestring sqlUpdate = "update mapping_parcels set city_state_zip=owner_citystate where city is null and fid=" + id;_dataAccess.ExcuateSQL(sqlUpdate);}}}}}</span>

3. Obtain the address code through latitude and longitude:

<span style="font-size:14px;">ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest();reverseGeocodeRequest.Credentials = new Credentials();reverseGeocodeRequest.Credentials.ApplicationId = "Arn2694QD8zXQJGN_IgecLbotcSVT1gTyRFfNSdPsIOO - yWjkkZRbwKcNEpCfelq";Location point = new Location();point.Latitude = double.Parse(lat);point.Longitude = double.Parse(lon);reverseGeocodeRequest.Location = point;GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");GeocodeResponse geocodeResponse = geocodeService.ReverseGeocode(reverseGeocodeRequest);if (geocodeResponse.Results != null){int iLength = geocodeResponse.Results.Length;if (iLength >= 1){string sConfidence = geocodeResponse.Results[0].Confidence.ToString();if (sConfidence == "Medium" || sConfidence == "High"){string sAddress = geocodeResponse.Results[0].DisplayName;if (sAddress.Contains("'")){sAddress = sAddress.Replace("'", "''");}string sStreetName = geocodeResponse.Results[0].Address.AddressLine;//string sState = geocodeResponse.Results[0].Address.AdminDistrict;string sCity = geocodeResponse.Results[0].Address.Locality;string sZip = geocodeResponse.Results[0].Address.PostalCode;string sLat = geocodeResponse.Results[0].Locations[0].Latitude.ToString();string sLon = geocodeResponse.Results[0].Locations[0].Longitude.ToString();string sMatchCodes = geocodeResponse.Results[0].MatchCodes[geocodeResponse.Results[0].MatchCodes.Length - 1].ToString();string sqlExist = "select * from mapping_geodata_boundary where code='NJ0415' and boundary.STContains(geometry::STGeomFromText('POINT(" + sLon + " " + sLat + ")', 0))=1";DataTable dtExist = _dataAccess.GetTables(sqlExist);if (dtExist.Rows.Count > 0){//Updatestring sqlUpdate = "update mapping_parcels set shape_street_name='" + sStreetName+ "',shape_city='" + sCity + "',shape_address='" + sAddress+ "',shape_zip='" + sZip + "',shape_matchcode='" + sMatchCodes + "' where fid=" + id;_dataAccess.ExcuateSQL(sqlUpdate);}}}}</span>


 

Geocodeservice of bingmap performs geographic location retrieval and reverse retrieval-Background implementation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.