通过IP地址获取ip所在的经纬度,直接获取经纬度是不可能的,只能通过腾讯、新浪、谷歌、网易等的ip纯真数据库。
获得ip所在的物理地址,然后通过google地图获取模糊的经纬度。
代码说明:
要想获得准确的经纬度,就得获取准备的物理地址,但是很明显。
无法获取精确的物理地址,因为有很多动态的ip地址。运营商也不可能把准确的物理地址给我们,所以
没可能。
例子,
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
<html>    
<head>    
<title>js获取ip地址利用谷歌地图获得经纬度-www.jb200.com</title>    
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />    
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false?ion=zh-CN"></script>    
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>    
</head>   
<script type="text/javascript">  
var  massage=null;  
function userip(ip){    
$.getScript("http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip="+ip,  function(){      
var prov=remote_ip_info["province"];        
var city=remote_ip_info["city"];           
var thisAddess=prov+city          
jsShow(thisAddess)         
}
);
}
function jsShow(address){     
var geocoder = new google.maps.Geocoder();     
if(geocoder){           
geocoder.geocode({'address': address }, function(results, status) {    
if (status == google.maps.GeocoderStatus.OK) {    
var GeoCode = ((results[0].geometry.location).toString().replace(/[()]/g, '')).split(",",2);    
var lat = parseFloat(GeoCode[0]);              
var lng = parseFloat(GeoCode[1]);          
var result=lat+','+lng;                 
alert('最后的结果为:'+result);        
}           
})        
} }
function mark(){  
var ip=$('#info').val();     
userip(ip);     
}      
</script>   
<body>     
输入ip地址:<input id="info" type="text">       
<input type="button" value="查询 " onclick="mark()">   
</body>   
</html>