>php教程 >PHP源码 >通过ip地址查询物理地址显示谷歌地图

通过ip地址查询物理地址显示谷歌地图

PHP中文网
PHP中文网원래의
2016-05-25 17:01:291819검색

     

1. [代码]通过ip地址查询物理地址显示谷歌地图

           

<html xmlns="http://www.w3.org/1999/xhtml">


<meta http-equiv="x-ua-compatible" content="ie=7" />

<meta http-equiv="Content-Type" content=&#39;text/html&#39;; charset=&#39;UTF-8&#39;;  />

<title>通过ip地址查询物理地址显示谷歌地图</title>


<!--调用谷歌地图js,zoom缩放倍数,center中心,mapTypeId地图类型-->  
<script type="text/javascript" src="http://ditu.google.com/maps/api/js?sensor=true"></script>  
<script language="javascript">  
 var geocoder;  
  var map;  
  function initialize() {  
    geocoder = new google.maps.Geocoder();  
    var latlng = new google.maps.LatLng(39.9493, 116.3975);  
    var myOptions = {  
      zoom: 15,  
      center: latlng,  
      mapTypeId: google.maps.MapTypeId.ROADMAP  
    }  
    var address = document.getElementById("address").value; 
	var img=&#39;http://www.google.com/images/logos/google_logo_41.png&#39;;

    if (geocoder) {  
      geocoder.geocode( { &#39;address&#39;: address}, function(results, status) {  
        if (status == google.maps.GeocoderStatus.OK) { 
          map.setCenter(results[0].geometry.location);  
          var marker = new google.maps.Marker({  
              map: map,   
              position: results[0].geometry.location,  
 			  title:&#39;位置&#39;,
              icon:img
      
          }); 
		  getInfor(map,marker,address,results[0].geometry.location);
		  addListener(marker)
        }   
      });  
    }  
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);  
  } 
   
  /*弹出信息窗口*/
  function getInfor(map,marker,address,ln){
 		var infowindow = new google.maps.InfoWindow({
       content: address+"\n"+ln
 });
infowindow.open(map,marker);

  }
  /*监听事件 经纬值*/
 function addListener(marker){
 var infowindow = new google.maps.InfoWindow({
       content:&#39;点点试试哦!&#39;,
pixelOffset:({width:50, height:20})
    });
google.maps.event.addListener(marker, &#39;click&#39;, function(event) {
        alert("你选择的经度是:"+event.latLng.lat()+"   纬度是:"+event.latLng.lat());
infowindow.open(map,marker);
    });
 }
  </script>  

<body onload="initialize()">
<p style="align:center">通过ip地址查询物理地址显示谷歌地图http://www.php.cn/;/p>
 <p id="map_canvas" style="width: 580px; height: 580px;align:center"></p>
  <p>
  <form method="post" action="">
输出ip地址:<input type="text" name="ip"  value="117.136.11.2">
<input type="submit" value="提交">


</form>
  位置: <input type="text" id="address" size="40" value="中国福建省福州市 移动" >
  </p>
</body>

                   

                   

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.