一、加入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进行地理位置正向和反向检索--后台实现的更多相关文章

  1. Bing Maps进阶系列二:使用GeocodeService进行地理位置检索

    Bing Maps进阶系列二:使用GeocodeService进行地理位置检索 在<Bing Maps进阶系列一:初识Bing Maps地图服务>里已经对GeocodeService的功能 ...

  2. (19)模型层 -ORM之msql 跨表查询(正向和反向查询)

    基于对象的跨表查询 基于对象的跨表查询'''正向和反向查询'''# 正向 ----> 关联字段在当前表中,从当前表向外查叫正向# 反向 ---> 关联字段不在当前表中,当当前表向外查叫反向 ...

  3. openresty开发系列2--nginx的简单安装,正向、反向代理及常用命令和信号控制介绍

    openresty开发系列2--nginx的简单安装,正向.反向代理及常用命令和信号控制介绍 一.nginx的安装下载及编译安装1.Nginx下载:nginx-1.13.0.tar.gz,下载到:/u ...

  4. Nginx的正向代理-反向代理-负载均衡

      正向代理与反向代理[总结]   1.前言 最近工作中用到反向代理,发现网络代理的玩法还真不少,网络背后有很多需要去学习.而在此之前仅仅使用了过代理软件,曾经为了访问google,使用了代理软件,需 ...

  5. 3、DNS服务器功能(正向、反向解析)

    实验目的: 建立gr.org域的主名称服务器.解析: 名称 IP 用途 ns.gr.org        192.168.170.3          名称服务器 www.gr.org     192 ...

  6. linux下正向代理/反向代理/透明代理使用说明

    代理服务技术对于网站架构部署时非常重要的,一般实现代理技术的方式就是在服务器上安装代理服务软件,让其成为一个代理服务器,从而实现代理技术.常用的代理技术分为正向代理.反向代理和透明代理.以下就是针对这 ...

  7. 理解squid的正向和反向代理

    1.相同点: 访问的走向都是:客户端 -> 代理服务器 ->真实服务器 ->代理服务器->客户端 2.不同点:正向代理语义上更侧重于,让代理服务器去帮忙请求某个网址.让代理服务 ...

  8. 正向代理&反向代理 简(fu)明(za)解释

    最近写的东西越来越偏向Web程序员了··· 你想读懂本篇,就要知道什么是Web服务器——装在世界上某个机房里某台机器里某个操作系统里的一个,对外(公网或者你能访问)服务各种你需要的信息的软件! 它可以 ...

  9. 003. 什么是 正向代理 & 反向代理

    正向代理: 客户端的代理: 反向代理: 服务端的代理:

随机推荐

  1. hdu 2828 Lamp 重复覆盖

    题目链接 给n个灯和m个开关, 每个灯可以由若干个开关控制, 每个开关也可以控制若干个灯, 问你能否找到一种开关的状态, 使得所有的灯都亮. 将灯作为列, 然后把每个开关拆成两行, 开是一行, 关是一 ...

  2. 转载文章:Windows Azure 七月份更新:SQL 数据库、流量管理器、自动伸缩、虚拟机

    转载文章:Windows Azure 七月份更新:SQL 数据库.流量管理器.自动伸缩.虚拟机 今天上午,我们发布了一些重大的 Windows Azure 更新.这些新的增强功能包括: · SQL 数 ...

  3. SQL高级查询

    高级查询: 一.多表链接 1,普通查询 select * from 表名,表名 where 表名.列名 = 表名.列名 2,join链接 select * from 表名 join 表名 on 表名. ...

  4. iOS禁用部分文件ARC

    TARGETS的build Phases中的Compile Source里修改文件备注文件参数设定: 增加-fobjc-arc来使单个文件 支持ARC,或者添加-fno-objc-arc使单个文件不支 ...

  5. Alisha’s Party(队列)

    Alisha’s Party Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  6. 许士彦:创业不走寻常路 APP最好时间已过

    从用户体验服务设计公司eico design到拥有两千多万用户的独立微博客户端Weico,再到备受欢迎的影像APP(微可拍,Weico Gif),Weico团队走过了一条不寻常的创业之路. 作为一家新 ...

  7. golang之匿名函数

    package main import "fmt" /* squares返回一个匿名函数 * 该匿名函数每次调用返回下一个数的平方 * func name(parameter-li ...

  8. 227. Basic Calculator

    1. 问题描述 Implement a basic calculator to evaluate a simple expression string. The expression string c ...

  9. Spring MVC详细示例实战教程【转】

    一.SpringMVC基础入门,创建一个HelloWorld程序 1.首先,导入SpringMVC需要的jar包. 2.添加Web.xml配置文件中关于SpringMVC的配置 1 2 3 4 5 6 ...

  10. GWT工程 —— HostedMode(宿主模式下调试) 所有的运行命令

    Unknown argument: -helpGoogle Web Toolkit 1.7.0HostedMode [-noserver] [-port port-number | "aut ...