刚在论坛和各位大神讨论了通过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> New Document </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>
本文介绍了一种通过IP地址获取地理位置信息的方法,利用Sina提供的API获取物理地址,并使用Google Maps API将地址转换为经纬度坐标。
2973

被折叠的 条评论
为什么被折叠?



