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. 什么是 正向代理 & 反向代理
		
正向代理: 客户端的代理: 反向代理: 服务端的代理:
 
随机推荐
- 防抖(Debouncing)和节流(Throttling)
			
onscoll防抖封装函数 scroll 事件本身会触发页面的重新渲染,同时 scroll 事件的 handler 又会被高频度的触发, 因此事件的 handler 内部不应该有复杂操作,例如 DOM ...
 - Hibernate之总结
			
以前做.net,最近做java项目,负责服务端的开发,直接用的jdbc,线程安全问题.缓存同步问题以及连接池什么的,都是手动写,不但麻烦而且容易出错.项目结束,赶快抽时间学了下hibernate,每天 ...
 - fcntl记录锁
			
#include<fcntl.h> int fcntl(fd,F_GETLK/F_SETLK/F_SETLKW,struct flock *flockptr); F_GETLK:测试flo ...
 - HBase源代码分析
			
http://www.docin.com/p-647062205.html http://blog.csdn.net/luyee2010/article/category/1285622 http:/ ...
 - GDKOI2015 Day2
			
P1 题目描述: 给出一个二分图,选择互不相交的边,使得边覆盖的点权和最大. solution: 简单DP,用树状数组维护最大值. 时间复杂度:$O(n \log n) $ P2 题目描述: 给出N个 ...
 - HDU 5972 Regular Number(ShiftAnd+读入优化)
			
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5972 [题目大意] 给出一个字符串,找出其中所有的符合特定模式的子串位置,符合特定模式是指,该子串 ...
 - poj1657---chessboard
			
对棋盘横纵坐标的解读 str1="f3" str2="e9" x=abs(str1[0]-str2[0]) y=abs(str1[1]-str1[1]) 如果x ...
 - leetcode 刷题之路 64 Construct Binary Tree from Inorder and Postorder Traversal
			
Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume tha ...
 - paip.c++ qt messagebox用法
			
paip.c++ qt messagebox用法 作者Attilax , EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.csdn.net ...
 - CouchDB简单应用
			
CouchDB是众多称作NoSQL解决方案中的一员.与众不同的是,CouchDB是一个面向文档的数据库,在它里面所有文档域(Field)都是以键值对的形式存储的.域(Field)可以是一个简单的键值对 ...