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

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

PHP中文网
Release: 2016-05-25 17:01:29
Original
1872 people have browsed it

     

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>
Copy after login

                   

                   

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template