利用Google Map API显示当前IP所在位置

Google的API确实强大,可以在电脑上显示“我的位置”,不过国内的并不是很准确,国外的精准度要高很多。

下面这个是利用QQ的一个地址获取当前IP,然后显示到Google地图上。

代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<HTML> 
 <HEAD> 
  <TITLE> Google Map By:Pop</TITLE> 
  <meta http-equiv="content-type" content="text/html; charset=utf-8"/> 
  <script type="text/javascript" src="http://fw.qq.com/ipaddress" charset="GBK"></script> 
  <script type="text/javascript" src="http://www.google.com/jsapi?key=abc"></script> 
  <script type="text/javascript" src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=true&amp;key=abc"></script> 
  <script type="text/javascript"> 
    function loadMaps(address) {  
      var map = new google.maps.Map2(document.getElementById("map"));  
      map.addControl(new GSmallMapControl());  
      map.addControl(new GMapTypeControl());  
      var geocoder = new GClientGeocoder();  
      geocoder.getLatLng(  
        address,  
        function(point) {  
          if (!point) {  
            alert(address + " not found");  
            map.setCenter(new GLatLng(35.8616600, 104.1953970), 4);  
          } else {  
            map.setCenter(point, 12);  
            var marker = new GMarker(point);  
            map.addOverlay(marker);  
            marker.openInfoWindowHtml(address);  
          }  
        }  
      );  
    }  
 
    function init() {  
      loadMaps(IPData.join(' '));  
    }  
    </script>   
 </HEAD> 
 
 <BODY onload="init()" onunload="GUnload()"> 
  <div id="map" style="width: 800px; height: 600px"></div>   
 </BODY> 
</HTML>

Google API 密钥生成地址:
http://code.google.com/intl/zh-CN/apis/ajaxsearch/signup.html

利用Google Map API制作的可查询输入IP地址所在位置的网站:
http://www.lizhijin.com/test/sdn/search.html
http://www.ip-adress.com/
http://www.seomoz.org/ip2loc

相关文章:
http://www.javaeye.com/topic/740640
http://www.lizhijin.com/view.php/Works/152.html

This entry was posted in Technology and tagged , , . Bookmark the permalink. 23,563 views

Related Posts

2 Responses to 利用Google Map API显示当前IP所在位置

  1. Pingback: 博客公园2010年9月份精华文章

Leave a Reply

Your email address will not be published. Required fields are marked *