BingMap的GeocodeService進行地理位置檢索和反向檢索--後台實現

來源:互聯網
上載者:User

標籤: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進行地理位置檢索和反向檢索--後台實現

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.