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,如需转载请自行联系原作者

相关文章
|
缓存 搜索推荐 安全
Google应该这样玩,你知道这些技巧吗?
网络让世界变成了“地球村”,拉近了世界各地人与人之间的距离;搜索引擎更是让我们在互联网上没有秘密可言,查找网页,查找信息,查找人,我们都离不开它。
187 0
Google应该这样玩,你知道这些技巧吗?
|
算法 自动驾驶 定位技术
未来,Google要怎么放卫星?
Google的这次收购,则会对未来人类生产生活产生重大影响。
175 0
Google Patent
http://patft.uspto.gov/netacgi/nph-Parser?Sect1=PTO2&Sect2=HITOFF&u=%2Fnetahtml%2FPTO%2Fsearch-adv.
2779 0
|
关系型数据库 Oracle
老是上不了 google scholar...
这段时间老是上不了 google scholar...   下载了最新的 host 也不行. 难道真是电脑有问题了? 网络有时也老是掉...   也好. 多休息休息. 人生难得几回清闲. 马上就要开学咯.   课还蛮多. 放轻松就好.
1634 0
|
安全 索引
Google安全视频
https://www.youtube.com/watch?v=ZRvWqF2JmUg&list=PLOU2XLYxmsII8UKqP84oaAxpwyryxbM-o&index=4 https://www.
757 0
google hunting
Hunting-Your-Memory-Heather-Adkins-Google.pdf The-Remediation-Ballet-Performing-the-Delicate-Dance-of-Clean-Up-Matt-Linton-Google.
848 0