google Map API实现地址解析
google Map API实现地址解析
Google map API的地址解析服务目前是不收费的,可以将详细的地址转化成经纬度。
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var geocoder;
function initialize() {
geocoder = new google.maps.Geocoder();
}
function codeAddress() {
var address = document.getElementById("address").value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
alert(results[0].geometry.location);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
</script>
</head>
<body οnlοad="initialize()">
<div>
<input id="address" type="textbox" value="Sydney, NSW">
<input type="button" value="Geocode" οnclick="codeAddress()">
</div>
</body>
</html>
______________________________________________________________
GoogleAPI进行地址解析和反向地址解析
目录(?)[+]
Google Geocoding API http://code.google.com/intl/zh-CN/apis/maps/documentation/geocoding/
地址解析请求
Google Geocoding API 请求必须采用以下形式:
http://maps.google.com/maps/api/geocode/output?parameters
其中,output
可以是以下值之一:
json
(建议)表示以 JavaScript 对象表示法 (JSON) 的形式输出xml
表示以 XML 的形式输出
有些参数是必需的,有些是可选的。根据网址的标准,所有参数均使用字符 & (&
) 分隔。下面枚举了这些参数及其可能的值。
Google Geocoding API 使用以下网址参数定义地址解析请求:
address
(必需)- 您要进行地址解析的地址。*或者
latlng
(必需)- 您希望获取的、距离最近的、可人工读取地址的纬度/经度文本值。*bounds
(可选)- 要在其中更显著地偏移地址解析结果的可视区域的边框。(有关详细信息,请参见下文的可视区域偏向。)region
(可选)- 区域代码,指定为 ccTLD(“顶级域”)双字符值。(有关详细信息,请参见下文的区域偏向。)language
(可选)- 传回结果时所使用的语言。请参见支持的区域语言列表。请注意,我们会经常更新支持的语言,因此该列表可能并不详尽。如果未提供language
,地址解析器将尝试尽可能使用发送请求的区域的本地语言。sensor
(必需)- 指示地址解析请求是否来自装有位置传感器的设备。该值必须为true
或false
。
* 请注意:您可以传递 address
或 latlng
进行查找。(如果传递 latlng
,则地址解析器执行反向地址解析。有关详细信息,请参阅反向地址解析。)
bounds
和 region
参数只会影响地址解析器返回的结果,但不能对其进行完全限制。
地址解析响应
地址解析响应将以网址请求路径中的 output
标记所指示的格式传回。
JSON 输出格式
在此示例中,Google Geocoding API 为针对“1600 Amphitheatre Parkway, Mountain View, CA”的查询请求一个 json
响应:
http://maps.google.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true_or_false
在此示例中,我们将 sensor
参数设为变量“true_or_false”以强调您必须将该值显式设置为 true
或 false
。
此请求传回的 JSON 如下所示。请注意,实际的 JSON 可能包含较少的空白。您不应假定请求之间的空白的数量或格式。
{"status": "OK","results": [ {"types": [ "street_address" ],"formatted_address": "1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA","address_components": [ {"long_name": "1600","short_name": "1600","types": [ "street_number" ]}, {"long_name": "Amphitheatre Pkwy","short_name": "Amphitheatre Pkwy","types": [ "route" ]}, {"long_name": "Mountain View","short_name": "Mountain View","types": [ "locality", "political" ]}, {"long_name": "California","short_name": "CA","types": [ "administrative_area_level_1", "political" ]}, {"long_name": "United States","short_name": "US","types": [ "country", "political" ]}, {"long_name": "94043","short_name": "94043","types": [ "postal_code" ]} ],"geometry": {"location": {"lat": 37.4219720,"lng": -122.0841430},"location_type": "ROOFTOP","viewport": {"southwest": {"lat": 37.4188244,"lng": -122.0872906},"northeast": {"lat": 37.4251196,"lng": -122.0809954}}}} ] }
请注意,JSON 响应包含两个根元素:
"status"
包含请求中的元数据。请参见下文的状态代码。"results"
包含一个经过地址解析的地址信息和几何图形信息的数组。
通常,对于地址查询,只会在 "results"
数组中传回一个条目,但在进行模糊地址查询时,地址解析器可能会传回多个结果。
请注意,如果您希望从结果中提取值,则这些结果通常需要进行解析。解析 JSON 相对来说较容易。有关一些设计模式建议,请参见解析 JSON。
————————————————————————————————————————————————————————————————————————
c#访问googleAPI
- 准备工作
要使用googleAPI 来开发自己的桌面应用程序,先要做下面的准备工作:
1. 首先在下面地址http://www.google.com/apis/download.html下载the Google Web APIs Developer's Kit。
2. 然后在下面地址https://www.google.com/accounts/NewAccount?continue=http://api.google.com/createkey&followup=http://api.google.com/createkey注册一个 license key 以使用google提供的搜索服务。
- 新建一个Google Search应用程序
1. 新建一个Windows From 项目命名为Google Search。
2. 添加Web引用,以便使用google web services。具体做法是将下载的the Google Web APIs Developer's Kit中的GoogleSearch.wsdl文件放入本地的服务器上,然后在VS中右键点击资源管理器中的引用,再选择添加Web引用,然后输入GoogleSearch.wsdl文件在本机服务器上的地址http://localhost/GoogleSearch.wsdl,更改Web引用名为GoogleSearch后,点击添加引用后返回。
3. 进行界面设计,添加3个控件,TextBox(用于输入关键字),Button(用于提交信息),RichTextBox(用于显示搜索结果信息)。如图:
4. 编写事件处理。
1) 添加命名空间。using Google_Search.googlesearch;
2) 双击Button控件,在Button的事件处理中添加下面的代码:
2
3 {
4
5 GoogleSearchService s = new GoogleSearchService();
6
7 GoogleSearchResult r = s.doGoogleSearch("NGYfW7dQFHKshnXPwvctLsaipk03YK2x", textBox1.Text, 0, 10, true, "", true, "", "", "");
8
9 ResultElement[] re = r.resultElements;
10
11 foreach (ResultElement n in re)
12
13 {
14
15 richTextBox1.AppendText(n.title+"\r");
16
17 richTextBox1.AppendText(n.snippet+"\r");
18
19 richTextBox1.AppendText(n.URL);
20
21 richTextBox1.AppendText("\n\r\r");
22
23 }
24
25 }
26
27
28
29 catch(Exception ee)
30
31 {
32
33 MessageBox.Show(ee.Message);
34
35 }
36
37
3) 按ctrl+F5就能测试应用程序了。
l GoogleSearchServices类doGoogleSearch方法
需要进行搜索先建立一个GoogleSearchServices 类的对象,然后调用doGoogleSearch方法取得信息。下面是google提供的对该方法的描述。
public doGoogleSearch(string key, string q, int start, int maxResults, bool filter, string restrict, bool safeSearch, string lr, string ie, string oe)
下面对各个参数进行介绍:
Key:这是由google提供的一个认证用的ID,可以在http://www.google.com/apis/申请。由于目前是测试阶段,每个ID一天只提供1000次的搜索服务请求。
q:这个就是要搜索的关键字。string类型
start:结果开始的索引数,从0开始。 int 类型
maxresults:返回的结果数的最大值,最大为10。int 类型
filter:用于标识是否对搜索的结果进行过滤,所进行的过滤是对于同一主机上的内容只返回1—2个结果。bool类型
restrict:用于限定搜索的国家或地区,如果为空,表示不限制。string 类型。
下表将列出所有能选的代号。
国家 |
代号 |
国家 |
代号 |
国家 |
代号 |
国家 |
代号 |
Andorra |
countryAD |
Estonia |
countryEE |
Kazakhstan |
countryKZ |
Qatar |
countryQA |
United Arab Emirates |
countryAE |
Egypt |
countryEG |
Lao People's Democratic Republic |
countryLA |
Reunion |
countryRE |
Afghanistan |
countryAF |
Western Sahara |
countryEH |
Lebanon |
countryLB |
Romania |
countryRO |
Antigua and Barbuda |
countryAG |
Eritrea |
countryER |
Saint Lucia |
countryLC |
Russian Federation |
countryRU |
Anguilla |
countryAI |
Spain |
countryES |
Liechtenstein |
countryLI |
Rwanda |
countryRW |
Albania |
countryAL |
Ethiopia |
countryET |
Sri Lanka |
countryLK |
Saudi Arabia |
countrySA |
Armenia |
countryAM |
European Union |
countryEU |
Liberia |
countryLR |
Solomon Islands |
countrySB |
Netherlands Antilles |
countryAN |
Finland |
countryFI |
Lesotho |
countryLS |
Seychelles |
countrySC |
Angola |
countryAO |
Fiji |
countryFJ |
Lithuania |
countryLT |
Sudan |
countrySD |
Antarctica |
countryAQ |
Falkland Islands (Malvinas) |
countryFK |
Luxembourg |
countryLU |
Sweden |
countrySE |
Argentina |
countryAR |
Micronesia, Federated States of |
countryFM |
Latvia |
countryLV |
Singapore |
countrySG |
American Samoa |
countryAS |
Faroe Islands |
countryFO |
Libyan Arab Jamahiriya |
countryLY |
St. Helena |
countrySH |
Austria |
countryAT |
France |
countryFR |
Morocco |
countryMA |
Slovenia |
countrySI |
Australia |
countryAU |
France, Metropolitan |
countryFX |
Monaco |
countryMC |
Svalbard and Jan Mayen Islands |
countrySJ |
Aruba |
countryAW |
Gabon |
countryGA |
Moldova |
countryMD |
Slovakia (Slovak Republic) |
countrySK |
Azerbaijan |
countryAZ |
United Kingdom |
countryUK |
Madagascar |
countryMG |
Sierra Leone |
countrySL |
Bosnia and Herzegowina |
countryBA |
Grenada |
countryGD |
Marshall Islands |
countryMH |
San Marino |
countrySM |
Barbados |
countryBB |
Georgia |
countryGE |
Macedonia, The FormerYugoslav Republic of |
countryMK |
Senegal |
countrySN |
Bangladesh |
countryBD |
French Quiana |
countryGF |
Mali |
countryML |
Somalia |
countrySO |
Belgium |
countryBE |
Ghana |
countryGH |
Myanmar |
countryMM |
Suriname |
countrySR |
Burkina Faso |
countryBF |
Gibraltar |
countryGI |
Mongolia |
countryMN |
Sao Tome and Principe |
countryST |
Bulgaria |
countryBG |
Greenland |
countryGL |
Macau |
countryMO |
El Salvador |
countrySV |
Bahrain |
countryBH |
Gambia |
countryGM |
Northern Mariana Islands |
countryMP |
Syria |
countrySY |
Burundi |
countryBI |
Guinea |
countryGN |
Martinique |
countryMQ |
Swaziland |
countrySZ |
Benin |
countryBJ |
Guadeloupe |
countryGP |
Mauritania |
countryMR |
Turks and Caicos Islands |
countryTC |
Bermuda |
countryBM |
Equatorial Guinea |
countryGQ |
Montserrat |
countryMS |
Chad |
countryTD |
Brunei Darussalam |
countryBN |
Greece |
countryGR |
Malta |
countryMT |
French Southern Territories |
countryTF |
Bolivia |
countryBO |
South Georgia and the South Sandwich Islands |
countryGS |
Mauritius |
countryMU |
Togo |
countryTG |
Brazil |
countryBR |
Guatemala |
countryGT |
Maldives |
countryMV |
Thailand |
countryTH |
Bahamas |
countryBS |
Guam |
countryGU |
Malawi |
countryMW |
Tajikistan |
countryTJ |
Bhutan |
countryBT |
Guinea-Bissau |
countryGW |
Mexico |
countryMX |
Tokelau |
countryTK |
Bouvet Island |
countryBV |
Guyana |
countryGY |
Malaysia |
countryMY |
Turkmenistan |
countryTM |
Botswana |
countryBW |
Hong Kong |
countryHK |
Mozambique |
countryMZ |
Tunisia |
countryTN |
Belarus |
countryBY |
Heard and Mc Donald Islands |
countryHM |
Namibia |
countryNA |
Tonga |
countryTO |
Belize |
countryBZ |
Honduras |
countryHN |
New Caledonia |
countryNC |
East Timor |
countryTP |
Canada |
countryCA |
Croatia (local name: Hrvatska) |
countryHR |
Niger |
countryNE |
Turkey |
countryTR |
Cocos (Keeling) Islands |
countryCC |
Haiti |
countryHT |
Norfolk Island |
countryNF |
Trinidad and Tobago |
countryTT |
Congo, The Democratic Republic of the |
countryCD |
Hungary |
countryHU |
Nigeria |
countryNG |
Tuvalu |
countryTV |
Central African Republic |
countryCF |
Indonesia |
countryID |
Nicaragua |
countryNI |
Taiwan |
countryTW |
Congo |
countryCG |
Ireland |
countryIE |
Netherlands |
countryNL |
Tanzania |
countryTZ |
Switzerland |
countryCH |
Israel |
countryIL |
Norway |
countryNO |
Ukraine |
countryUA |
Cote D'ivoire |
countryCI |
India |
countryIN |
Nepal |
countryNP |
Uganda |
countryUG |
Cook Islands |
countryCK |
British Indian Ocean Territory |
countryIO |
Nauru |
countryNR |
United States Minor Outlying Islands |
countryUM |
Chile |
countryCL |
Iraq |
countryIQ |
Niue |
countryNU |
United States |
countryUS |
Cameroon |
countryCM |
Iran (Islamic Republic of) |
countryIR |
New Zealand |
countryNZ |
Uruguay |
countryUY |
China |
countryCN |
Iceland |
countryIS |
Oman |
countryOM |
Uzbekistan |
countryUZ |
Colombia |
countryCO |
Italy |
countryIT |
Panama |
countryPA |
Holy See (Vatican CityState) |
countryVA |
Costa Rica |
countryCR |
Jamaica |
countryJM |
Peru |
countryPE |
Saint Vincent and the Grenadines |
countryVC |
Cuba |
countryCU |
Jordan |
countryJO |
French Polynesia |
countryPF |
Venezuela |
countryVE |
Cape Verde |
countryCV |
Japan |
countryJP |
Papua New Guinea |
countryPG |
Virgin Islands (British) |
countryVG |
Christmas Island |
countryCX |
Kenya |
countryKE |
Philippines |
countryPH |
Virgin Islands (U.S.) |
countryVI |
Cyprus |
countryCY |
Kyrgyzstan |
countryKG |
Pakistan |
countryPK |
Vietnam |
countryVN |
Czech Republic |
countryCZ |
Cambodia |
countryKH |
Poland |
countryPL |
Vanuatu |
countryVU |
Germany |
countryDE |
Kiribati |
countryKI |
St. Pierre and Miquelon |
countryPM |
Wallis and Futuna Islands |
countryWF |
Djibouti |
countryDJ |
Comoros |
countryKM |
Pitcairn |
countryPN |
Samoa |
countryWS |
Denmark |
countryDK |
Saint Kitts and Nevis |
countryKN |
Puerto Rico |
countryPR |
Yemen |
countryYE |
Dominica |
countryDM |
Korea, Democratic People's Republic of |
countryKP |
Palestine |
countryPS |
Mayotte |
countryYT |
Dominican Republic |
countryDO |
Korea, Republic of |
countryKR |
Portugal |
countryPT |
Yugoslavia |
countryYU |
Algeria |
countryDZ |
Kuwait |
countryKW |
Palau |
countryPW |
South Africa |
countryZA |
Ecuador |
countryEC |
Cayman Islands |
countryKY |
Paraguay |
countryPY |
Zambia |
countryZM |
Zaire |
countryZR |
safeSearch:使用一个bool值表示是否过滤垃圾信息。
lr:对语言的限制,string类型。可选代号如下表:
语言 |
代号 |
语言 |
代号 |
|
Arabic |
lang_ar |
Icelandic |
lang_is |
|
Chinese (S) |
lang_zh-CN |
Italian |
lang_it |
|
Chinese (T) |
lang_zh-TW |
Japanese |
lang_ja |
|
Czech |
lang_cs |
Korean |
lang_ko |
|
Danish |
lang_da |
Latvian |
lang_lv |
|
Dutch |
lang_nl |
Lithuanian |
lang_lt |
|
English |
lang_en |
Norwegian |
lang_no |
|
Estonian |
lang_et |
Portuguese |
lang_pt |
|
Finnish |
lang_fi |
Polish |
lang_pl |
|
French |
lang_fr |
Romanian |
lang_ro |
|
German |
lang_de |
Russian |
lang_ru |
|
Greek |
lang_el |
Spanish |
lang_es |
|
Hebrew |
lang_iw |
Swedish |
lang_sv |
|
Hungarian |
lang_hu |
Turkish |
lang_tr |
ie:输入所使用的字符编码。这个参数将被忽略,所有的输入都将采用UTF-8。
oe:输出所使用的字符编码。这个参数将被忽略,所有的输出都将采用UTF-8
。
通过对这个方法的各个参数的设定可以是自己的应用程序在搜索方面更加人性化。具体使用时可以通过各种控件来收集这些信息。
l GoogleSearchResult类
这个类用于存储搜索结果,下面介绍这个类的一些重要属性:
1. estimatedTotalResultsCount 所有与关键字有关的信息的总数。
2. searchTime 提交信息到返回信息所用的时间。
3. searchTips 根据关键字提供一些与关键字相关的关键字,供选择。
4. resultElements 返回一个数组,用于存储返回结果的每一项。
l Result Element类
这个类的是搜索的结果中的每一项,所有的结果处理都依靠这个类。下面是这个类的一些属性的介绍:
1. URL 显示结果网页的url。
2. snippet 返回在目标网页中摘录一些包含关键字片段。
3. title 目标网页的标题。
4. hostname 该参数显示目标网页所在的主机明。
5. summary 如果目标网页在ODP 目录中存在,则返回摘要信息。
6. directoryTitle 显示ODP 目录的标题。
通过这两个类可以取得各种与查询有关的信息,通过以上的介绍,基本可以使用googleAPI提供的全部功能。
google Map API实现地址解析相关推荐
- java google map_java如何通过google map api实现地址解析
地址解析就是将地址(如:广东省广州市)转换为地理坐标(如经度:113.26442,纬度:23.129074)的过程.google map api提供两种方法实现地址解析. 第一种,是通过使用 GCli ...
- google map Api接口整理
Google Map Api接口整理 一:基本知识: 1. 使用谷歌地图 API 的第一步就是要注册一个 API 密钥,需要注意一下两点: 1.如果使用 API 的页面还没有发布,只是在本地调试,可以 ...
- Java 调用Google Map Api解析地址,解析经纬度实例
Java 调用Google Map Api解析地址,解析经纬度实例 使用google地图的反向地址解析功能,提供一个经纬度得到对应地址,或者给出模糊地址,得到经纬度,放在java后台代码中处理,这个使 ...
- 主流电子地图API比较 google map api, mapabc ,yahoo地图
主流电子地图API比较 Google Maps API : Google Maps API 基于Google Maps,能够使用 JavaScript 将 Google Maps 嵌入网页中.API ...
- 关于Google Map API V2 版本的定位与导航
近来,在关注安卓手机上的GoogleMap应用的开发,但是目前官方API版本网页版已经升级到V3版,而对于Android的支持也已经升级到V2版本,虽然Google说继续对V1版提供服务,但是不再提供 ...
- 分享两篇Google Map API的介绍
这两篇文章也不知道我是什么时候下载下来的,一直丢在桌面上没有看,但终于在年后无聊就看了一下,结果让我心潮澎湃,一起哈成了"都让Google做了我们还做什么?(WebMap方向)"一 ...
- Google Map API V3开发(5)
Google Map API V3开发(1) Google Map API V3开发(2) Google Map API V3开发(3) Google Map API V3开发(4) Google M ...
- 【转】在你的博客中添加Google地图(Use Google Map API On Your Bolg)
在你的博客中添加Google地图(Use Google Map API On Your Bolg) *+申请一组 Google Maps API Key 在使用 Google Maps API 之前, ...
- 申请google Map api key for android
申请android google map API key 1.首先找到debug keystore位置: 打开Eclipse--->Windows--->Preferences---> ...
最新文章
- Directx11教程(61) tessellation学习(3)
- zabbix3.2+Grafana4.0实现可视化监控图形
- 关于ASP.NET中fileupload控件的缺点
- webGIS(离线版)研究路线归总
- boost::mp11::mp_product相关用法的测试程序
- Linux crond实例
- WAF指纹识别和XSS过滤器绕过技巧
- Ubuntu配置IPFS的环境
- python循环括号_Python3中小括号()、中括号[]、花括号{}的区别详解
- class在线反编译_Java在线诊断-Arthas生产代码热更新
- springboot中,页面访问不到静态资源
- X64_Xcelera-CL_PX4采集卡测试记录
- Atitit 信息管理 艾提拉著作 CAPT1信息源数据源 目录 1. 数据元的数据格式 图片 文本 视频 音频	2 2. 按照应用功能使用分类	2 2.1. Diary Cyarlog	2
- eclipse使用教程(图文)
- 2022年【CSDN毎周小结】
- 计算机c盘用户里的APPDATA,appdata是什么文件夹 C盘Appdata文件能不能删除?
- 微软技术探究之FASTER
- 电子竞技作为一项全新的竞技体育项目,近年来发展迅猛,未来发展趋势
- unity 如何实现一个日志上报系统
- oracle数据库存储管理--ASM