標籤:des style blog http io os 使用 ar strong
一、添加GeocodeService的Web服務引用
地理編碼服務(GeocodeService)是以WCF技術發布的一個Web服務,地圖編碼服務提供了以一個有效物理地址在地圖上匹配其對應的地圖地址(既地理經度和緯度座標)和以地理經度和緯度座標進行反向匹配物理地址路徑的功能。要使用該服務需添加該服務(http://dev.virtualearth.net/webservices/v1/geocodeservice/GeocodeService.svc)的Web服務引用,如
二、通過地址獲得經緯度的code:
<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>
三、通過經緯度獲得地址的Code:
<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>
BingMap的GeocodeService進行地理位置檢索和反向檢索--後台實現