BingMap的GeocodeService进行地理位置正向和反向检索--后台实现
一、加入GeocodeService的Web服务引用
地理编码服务(GeocodeService)是以WCF技术公布的一个Web服务,地图编码服务提供了以一个有效的物理地址在地图上匹配其相应的地图地址(既地理经度和纬度坐标)和以地理经度和纬度坐标进行反向匹配物理地址路径的功能。要使用该服务需加入该服务(http://dev.virtualearth.net/webservices/v1/geocodeservice/GeocodeService.svc)的Web服务引用,例如以下图
二、通过地址获得经纬度的code:
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)
{
//Update
string sqlUpdate = "update mapping_parcels set city_state_zip=owner_citystate where city is null and fid=" + id;
_dataAccess.ExcuateSQL(sqlUpdate);
}
}
}
}
}
三、通过经纬度获得地址的Code:
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)
{
//Update
string 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);
}
}
}
}
BingMap的GeocodeService进行地理位置正向和反向检索--后台实现的更多相关文章
- Bing Maps进阶系列二:使用GeocodeService进行地理位置检索
Bing Maps进阶系列二:使用GeocodeService进行地理位置检索 在<Bing Maps进阶系列一:初识Bing Maps地图服务>里已经对GeocodeService的功能 ...
- (19)模型层 -ORM之msql 跨表查询(正向和反向查询)
基于对象的跨表查询 基于对象的跨表查询'''正向和反向查询'''# 正向 ----> 关联字段在当前表中,从当前表向外查叫正向# 反向 ---> 关联字段不在当前表中,当当前表向外查叫反向 ...
- openresty开发系列2--nginx的简单安装,正向、反向代理及常用命令和信号控制介绍
openresty开发系列2--nginx的简单安装,正向.反向代理及常用命令和信号控制介绍 一.nginx的安装下载及编译安装1.Nginx下载:nginx-1.13.0.tar.gz,下载到:/u ...
- Nginx的正向代理-反向代理-负载均衡
正向代理与反向代理[总结] 1.前言 最近工作中用到反向代理,发现网络代理的玩法还真不少,网络背后有很多需要去学习.而在此之前仅仅使用了过代理软件,曾经为了访问google,使用了代理软件,需 ...
- 3、DNS服务器功能(正向、反向解析)
实验目的: 建立gr.org域的主名称服务器.解析: 名称 IP 用途 ns.gr.org 192.168.170.3 名称服务器 www.gr.org 192 ...
- linux下正向代理/反向代理/透明代理使用说明
代理服务技术对于网站架构部署时非常重要的,一般实现代理技术的方式就是在服务器上安装代理服务软件,让其成为一个代理服务器,从而实现代理技术.常用的代理技术分为正向代理.反向代理和透明代理.以下就是针对这 ...
- 理解squid的正向和反向代理
1.相同点: 访问的走向都是:客户端 -> 代理服务器 ->真实服务器 ->代理服务器->客户端 2.不同点:正向代理语义上更侧重于,让代理服务器去帮忙请求某个网址.让代理服务 ...
- 正向代理&反向代理 简(fu)明(za)解释
最近写的东西越来越偏向Web程序员了··· 你想读懂本篇,就要知道什么是Web服务器——装在世界上某个机房里某台机器里某个操作系统里的一个,对外(公网或者你能访问)服务各种你需要的信息的软件! 它可以 ...
- 003. 什么是 正向代理 & 反向代理
正向代理: 客户端的代理: 反向代理: 服务端的代理:
随机推荐
- HTTP协议中的1xx,2xx,3xx,4xx,5xx状态码分别表示什么,列举常见错误码及含义
转自:http://m.blog.csdn.net/blog/u013857407/21741847 HTTP协议状态码,是指在HTTP协议运作中由客户端发出请求连接,服务端建立连接,客户端发出HTT ...
- jira 解决结果配置
jira 的配置比较繁琐,有很多的小细节,使用中出现了各种小问题,总结梳理下 1.解决结果 问题1:编辑了任务后,解决结果变成了已解决 找到编辑任务所对应的界面方案,将解决结果字段从界面配置里移除 问 ...
- 转 ——eclipse下进行Python开发 环境配置
python for eclipse插件安装1.下载python for eclipsepython for eclipse下载地址,如:org.python.pydev.feature-1.6.3. ...
- fcntl记录锁
#include<fcntl.h> int fcntl(fd,F_GETLK/F_SETLK/F_SETLKW,struct flock *flockptr); F_GETLK:测试flo ...
- Storm csdn
blog.csdn.net/lonelytrooperblog.csdn.net/leytton http://my.oschina.net/apdplat/blog/308396
- JS 网页打印解决方案
这些日子真是太忙了,项目太多了公司总是加班,而且这些项目中好多都用到的打印,所以学习了一段时间js的打印. 其实原来只是用到了简单的功能,现在要深入的了解才发现原来ie的网页打印也是如此的强大. 以下 ...
- javascript编辑器预览模式解密
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- zoj2729 Sum Up(模拟)
Sum Up Time Limit: 2 Seconds Memory Limit: 65536 KB Vivid has stored a piece of private informa ...
- Objective-C官方文档翻译 Block
版权声明:原创作品,谢绝转载!否则将追究法律责任. 一个Objective-c类定义了一个对象结合数据相关的行为.有时候,这使得他有意义的表达单个任务或者单元的行为.而不是集合的方法. blocks是 ...
- matlab如何保存figure中去掉白边的图片
输出图片成可直接调入的灰度图,设置输出图片空白边距,以及调整图片大小,纵横比. 一.先显示图片,imshow.如果是plot,或者newplot,直接看“三”.imshow(strain_image, ...