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. 什么是 正向代理 & 反向代理
正向代理: 客户端的代理: 反向代理: 服务端的代理:
随机推荐
- 练习-checkbox 全选 ,反选, 单选,以及取值
1.方法1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w ...
- 配件BOM定义限制(只定义配件的)
应用 Oracle Bill Of Materiel 层 Level Function 函数名 Funcgtion Name BOM_BOMFDBOM 表单名 Form Name BOMFDBOM ...
- web.config中<customErrors>节点
错误提示: “/”应用程序中的服务器错误.------------------------------------------------------------------------------- ...
- [原]命令模式在MVC框架中的应用
其实在项目开发中,我们使用了大量的设计模式,只是这些设计模式都封装在框架中了,如果你想要不仅仅局限于简单的使用,就应该深入了解框架的设计思路. 在MVC框架中,模式之一就是命令模式,先来看看模式是如何 ...
- Unix/Linux环境C编程入门教程(12) openSUSECCPP以及Linux内核驱动开发环境搭建
1. openSUSE是一款优秀的linux. 2.选择默认虚拟机 3.选择稍后安装操作系统 4.选择linux opensuse 5. 选择默认虚拟机名称 6.设置处理器为双核. 7.内存设置为2 ...
- 字符串比较必须使用strcmp
char s1[]="this" char *s2 = "this" if(s1=="this"){ printf("s1 is ...
- Mac设置
Mac系统的环境变量,加载顺序为: /etc/profile /etc/paths ~/.bash_profile ~/.bash_login ~/.profile ~/.bashrc
- qt 5.1.1 on CentOS 6.4
Overview If you are trying to install Qt and Qwt [qwt.sourceforge.net] (Qt Widgets for Technical App ...
- python SyntaxError: Non-ASCII character '\xd5' in file
我使用的是python2.7, 在pycharm想运行程序,但是却报出了SyntaxError: Non-ASCII character '\xd5' in file 原因是因为源码中包含了中文注释, ...
- 高德地图API
这周计划: 周一 早上 (高德地图API) 中午写(IFE PART ONE) 下午(高德地图API) 下班(IFE PART ONE)