Google Geocoding

简介:


    地理信息最重要的信息就是地理位置,如何能快速有效的定位到我们所期望的地方,是每一个GIS系统需要认真考虑的问题,根据属性定位空间位置和选择空间位置查询属性信息,成为现在绝大多数GIS系统的基本功能。

    同样是位置查询,Geocoding的功能更贴近我们的生活,它可以将具体的地址信息转换为空间坐标点(X/Y),Reverse Geocoding则是将一个空间坐标点转换为具体的地址信息。Geocoding规则建立需要城市街道命名规范、完整,是中国城市所欠缺的,需要逐步完善。ArcGIS很早就提供了对Geocoding支持,现在Google也实现了相似的功能,包括Geocoding和Reverse Geocoding,加上Google Map/Earth,Google在逐步成为一个面向大众网络GIS基础服务中心。

    GClientGeocoder对象的getLatLng和getLocations分别实现Geocoding和Reverse Geocoding。

    Geocoding

复制代码
var  map  =   new  GMap2(document.getElementById( " map_canvas " ));
var  geocoder  =   new  GClientGeocoder();
function  showAddress(address) {
    geocoder.getLatLng(
        address,
        
function (point) {
            
if  ( ! point) {
                alert(address 
+   "  not found " );
            } 
else  {
                map.setCenter(point, 
13 );
                
var  marker  =   new  GMarker(point);
                map.addOverlay(marker);
                marker.openInfoWindowHtml(address);
            }
        }
    );
}
复制代码


    Reverse Geocoding

复制代码
var  map;
var  geocoder;
var  address;
function  initialize() {
    map 
=   new  GMap2(document.getElementById( " map_canvas " ));
    map.setCenter(
new  GLatLng( 40.730885 , - 73.997383 ),  15 );
    map.addControl(
new  GLargeMapControl);
    GEvent.addListener(map, 
" click " , getAddress);
    geocoder 
=   new  GClientGeocoder();
}
function  getAddress(overlay, latlng) {
    
if  (latlng  !=   null ) {
        address 
=  latlng;
        geocoder.getLocations(latlng, showAddress);
    }
}
function  showAddress(response) {
    map.clearOverlays();
    
if  ( ! response  ||  response.Status.code  !=   200 ) {
        alert(
" Status Code: "   +  response.Status.code);
    } 
else  {
        place 
=  response.Placemark[ 0 ];
        point 
=   new  GLatLng(place.Point.coordinates[ 1 ],place.Point.coordinates[ 0 ]);
        marker 
=   new  GMarker(point);
        map.addOverlay(marker);
        marker.openInfoWindowHtml(
            
' <b>orig latlng:</b> '   +  response.name  +   ' <br/> '   +  
            
' <b>latlng:</b> '   +  place.Point.coordinates[ 0 +   " , "   +  place.Point.coordinates[ 1 +   ' <br> '   +  
            
' <b>Status Code:</b> '   +  response.Status.code  +   ' <br> '   +  
            
' <b>Status Request:</b> '   +  response.Status.request  +   ' <br> '   +  
            
' <b>Address:</b> '   +  place.address  +   ' <br> '   +  
            
' <b>Accuracy:</b> '   +  place.AddressDetails.Accuracy  +   ' <br> '   +  
            
' <b>Country code:</b>  '   +  place.AddressDetails.Country.CountryNameCode);
    }
}
复制代码

    Reverse Geocoding定位的具体地址并非精确的结果,而是满足一定容差值的地址结果集,ArcGIS Geocode可以设置结果的正确率,如仅列举出符合程度为60%及以上的地址,如果没有搜索到结果,Google返回G_GEO_UNKNOWN_ADDRESS (602),Geocoding结果保存在客户端cache中,加快执行相同geocoding时的速度,具体方法为GClientGeocoder.setCache()。

    上述方法都是在客户端执行geocoding操作,除了使用GClientGeocoder之外,还可以通过HTTP执行geocoding,方便服务器端的调试:


    To access the Maps API Geocoder, send a request to http://maps.google.com/maps/geo? with the following parameters in the URI:

    q (required) — The address that you want to geocode. 
    key (required) — Your API key. 
    output (required) — The format in which the output should be generated. The options are xml, kml, csv, or (default) json. 
    ll (optional) — The {latitude,longitude} of the viewport center expressed as a comma-separated string (e.g. "ll=40.479581,-117.773438" ). This parameter only has meaning if the spn parameter is also passed to the geocoder. 
    spn (optional) — The "span" of the viewport expressed as a comma-separated string of {latitude,longitude} (e.g. "spn=11.1873,22.5" ). This parameter only has meaning if the ll parameter is also passed to the geocoder. 
    gl (optional) — The country code, specified as a ccTLD ("top-level domain") two-character value. 
    Note: The gl and spn,ll viewport parameters will only influence, not fully restrict, results from the geocoder.

    In this example, we request the geographic coordinates of Google's headquarters:
    http://maps.google.com/maps/geo?q=1600+Amphitheatre+Parkway,+Mountain+View,+CA&output=xml&key=abcdefg


本文转自Flyingis博客园博客,原文链接:http://www.cnblogs.com/flyingis/archive/2008/11/09/1329287.html,如需转载请自行联系原作者

相关文章
|
iOS开发 MacOS 数据安全/隐私保护
|
9月前
|
存储 人工智能 搜索推荐
WiseMindAI:一款AI智能知识库,数据完全本地化,支持文档对话、10+种文档、10+AI大模型等
WiseMindAI 是一款由 Chris 开发的 AI 智能学习助手,支持数据完全本地化存储,确保用户隐私安全。它兼容多种文档格式(如 PDF、Markdown 等),并提供 AI 文档总结、智能笔记、沉浸式翻译、知识卡片生成等功能。此外,WiseMindAI 支持 10+ 大语言模型和自定义 AI 插件,适用于 Windows 和 Mac 平台,支持简体中文、繁体中文及英文。
854 74
WiseMindAI:一款AI智能知识库,数据完全本地化,支持文档对话、10+种文档、10+AI大模型等
|
8月前
|
数据采集 人工智能 监控
40.8K star!让AI帮你读懂整个互联网:Crawl4AI开源爬虫工具深度解析
Crawl4AI 是2025年GitHub上备受瞩目的开源网络爬虫工具,专为AI时代设计。它不仅能抓取网页内容,还能理解页面语义结构,生成适配大语言模型的训练数据格式。上线半年获4万+星标,应用于1200+AI项目。其功能亮点包括智能内容提取引擎、AI就绪数据管道和企业级特性,支持动态页面处理、多语言识别及分布式部署。技术架构基于Python 3.10与Scrapy框架,性能卓越,适用于AI训练数据采集、行业情报监控等场景。相比Scrapy、BeautifulSoup等传统工具,Crawl4AI在动态页面支持、PDF解析和语义分块方面更具优势
3087 0
40.8K star!让AI帮你读懂整个互联网:Crawl4AI开源爬虫工具深度解析
|
10月前
|
存储 自然语言处理 自动驾驶
基于LLM打造沉浸式3D世界
阿里云数据可视化产品DataV团队一直在三维交互领域进行前沿探索,为了解决LLMs与3D结合的问题,近期在虚幻引擎内结合通义千问大模型家族打造了一套基于LLM的实时可交互3D世界方案,通过自然语言来与引擎内的3D世界进行交互。
1038 160
|
Linux iOS开发 MacOS
【MCP教程系列】阿里云百炼MCP全面配置指南:涵盖NPX、UVX、SSE及Streamable HTTP
本文详细介绍如何在阿里云百炼平台及Windows、Linux、MacOS系统中正确配置MCP服务的JSON文件。内容涵盖三种MCP服务配置:npx(基于Stdio)、uvx(Python工具运行)和SSE(服务器发送事件)。同时解析Streamable HTTP作为新一代传输方案的优势与应用,帮助用户掌握每个参数的具体用途及使用方法,解决配置过程中可能遇到的问题,提供完整示例和扩展信息以优化设置体验。
3958 11
|
8月前
|
弹性计算 固态存储 ice
阿里云服务器ECS内存型2核16G、4核32G和8核64G配置实例、费用和性能参数表
本文整理了2025年阿里云服务器租赁价格表,涵盖2核16G、4核32G和8核64G配置收费标准。CPU内存比为1:8,提供多种实例规格如ECS内存型r8i、通用算力型u1等。价格由CPU内存、公网带宽及系统盘组成,支持优惠折扣(年付6.7折起)。文中详细列出各配置参考价格、公网带宽与系统盘收费,并对比不同实例规格性能,如Intel Xeon和AMD EPYC处理器系列,帮助用户选择高性价比方案。具体价格以阿里云官网为准。
1271 4
|
Java 调度 开发者
spring的@Scheduled()有几种定时模式?
【10月更文挑战第12天】spring的@Scheduled()有几种定时模式?
513 1
|
人工智能 自然语言处理 搜索推荐
国内可用的 Web Search API,可以平替Bing Search API
近期人们发现,AI对搜索引擎的需求远远超过人类。这个团队专为AI打造搜索引擎,上线仅60天就已被调用超30万次。
国内可用的 Web Search API,可以平替Bing Search API

热门文章

最新文章