下午看了看Google提供的API,发现Google现在提供的API是越来越多了,什么方面的都有,数据免费让你用,测绘地图的卫星也免费让你用……
没事做就学用了一下Google Map API,给的函数不是特别多,但实际应用中数据的类型和源才是重点,用了几个基本的函数做了这个小东西,通过在输入框中输入一个IP或者域名即可在地图上定位显示该IP或域名对应的主机坐在的位置,同时再给出一个国家、城市、经纬度等信息……
在此用到了GEOIP免费IP数据库,可以去http://www.maxmind.com/download/geoip下载
第一次尝试Web API,以后可能还会尝试其他的API,也会对Google Map API做更深一步的学习,用别人的东西感觉挺好的……
PHP代码
- <?php
- header('Content-type: text/html;charset=GB2312');
- include("geoipcity.inc");
- include("geoipregionvars.php");
- function getip(){
- if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
- $ip = getenv("HTTP_CLIENT_IP");
- else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
- $ip = getenv("HTTP_X_FORWARDED_FOR");
- else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
- $ip = getenv("REMOTE_ADDR");
- else if (isset($_SERVER["REMOTE_ADDR"]) && $_SERVER["REMOTE_ADDR"] && strcasecmp($_SERVER["REMOTE_ADDR"], "unknown"))
- $ip = $_SERVER["REMOTE_ADDR"];
- else
- $ip = "unknown";
- return $ip;
- }
- if(emptyempty($_GET['q'])) {
- $ip = getip();
- if($ip == "unknown") {
- echo 'alert("无法取得客户端IP");';
- die();
- }
- } else {
- $pattern = "/^((1?\d?\d|(2([0-4]\d|5[0-5])))\.){3}(1?\d?\d|(2([0-4]\d|5[0-5])))$/";
- if(preg_match($pattern,$_GET['q'])) {
- $ip = $_GET['q'];
- } else {
- $ip = gethostbyname($_GET['q']);
- if(preg_match($pattern,$_GET['q'])) {
- echo 'alert("查询地址有误");';
- die();
- }
- }
- }
- $gi = geoip_open("./GeoLiteCity.dat",GEOIP_STANDARD);
- $record = GeoIP_record_by_addr($gi,$ip);
- geoip_close($gi);
- if($record) {
- echo 'loadInfo('.
- '"'.$_GET['q'].'",'.
- '"'.$ip.'",'.
- '"'.$record->country_code.'",'.
- '"'.$record->country_code3.'",'.
- '"'.$record->country_name.'",'.
- '"'.$GEOIP_REGION_NAME[$record->country_code][$record->region].'",'.
- '"'.$record->city.'",'.
- $record->latitude.','.$record->longitude.')';
- } else {
- echo 'alert("数据库里不存在该IP的信息");';
- }
- ?>
XML/HTML代码
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
- <title>Google Maps JavaScript API Example</title>
- <script src="js/jquery/jquery.pack.js"
- type="text/javascript"></script>
- <script charset="utf-8" src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAHNhEpt8X-NNdY903GRqUZxSXPx9oqQLJ7Iscw6Eb65jR2kkxxxSwxSxR-C6LwGyWiSUfXSiLCnV8jw"
- type="text/javascript"></script>
- <script type="text/javascript">
- var map,marker;
- $(document).ready(function () {
- if (GBrowserIsCompatible()) {
- map = new GMap2(document.getElementById("map"));
- map.setCenter(new GLatLng(39.92,116.46), 18);
- map.addControl(new GSmallMapControl());
- map.addControl(new GMapTypeControl());
- map.setMapType(G_HYBRID_MAP);
- getInfo("");
- }
- });
- function parseEnter(event,q) {
- if(event.keyCode == 13 || event.keyCode == 10)
- getInfo(q);
- }
- function getInfo(q) {
- //GDownloadUrl("search.php?q="+q, function (data) {eval(data);});
- $("#loading").ajaxStart(function(){$(this).show();}).ajaxComplete(function(){$(this).hide();});
- $.ajax({
- type: "get",
- url: "search.php?q="+q,
- beforeSend: function() {
- },
- success: function(data) {
- eval(data);
- }
- });
- }
- function loadInfo(q,ip,country_code,country_code3,country,region,city,latitude,longtitude) {
- var info = "<div align=left style=overflow:x;font-size:12px>"
- + "<span style=font-size:14px;><b><a target=_blank href=http://" + q + ">" + q + "</a></b></span><br>"
- + "<b>IP:</b> " + ip + "<br>"
- + "<b>国家:</b> " + country + "<br>"
- + "<b>代码:</b> " + country_code + "<br>"
- + "<b>省份:</b> " + city + "<br>"
- + "<b>城市:</b> " + region + "<br>"
- + "<b>经度:</b> " + longtitude + "<br>"
- + "<b>纬度:</b> " + latitude + "<br>"
- + "<span align=right><b><a target=_blank href=http://lizhijin.com>LiZhiJin.com</a></b></span><br>";
- var point = new GLatLng(latitude,longtitude);
- map.panTo(point);
- if(marker) {
- map.closeInfoWindow();
- map.removeOverlay(marker);
- }
- marker = new GMarker(point);
- map.addOverlay(marker);
- marker.openInfoWindowHtml(info);
- }
- </script>
- </head>
- <body onunload="GUnload()" style="text-align:center">
- <h3>域名或IP在Google Map上的定位(首次加载显示您的位置)</h3>
- <div id="result">
- <form onsubmit="return false;">
- 输入IP或域名(不需要http://):<input type="text" maxlength="100" size="25" name="q" id="q" onkeypress="parseEnter(event,this.value)" /> <input type="button" value="查询" onclick="getInfo(q.value)" /> <span id="loading" style="display:none">正在查询...</span>
- </form>
- </div>
- <div id="map" style="width: 500px; height: 300px"></div>
- </body>
- </html>


厚积薄发,有的放矢――李开复博士给中国计算机系学生的建议
Large
Middle
Small
Attachment:

views(11776)
view comments(98)
add comment


Comments:
It seems that you are interested in our products, but you did not buy it. Could you please tell us the reason or would you give us some suggestions about our web or our products, so that we can serve you better. Thank you!
We are the legal agent and our factory is a result of a long history of dedication, workmanship and attention to details.So Our products are 100% authentic.
Discounts are as follows:
Discount Coupon
3% discount for 1 item, the code: 3h150f4m79
5% discount for 2 items, the code: cacfb9cb1e
7% discount for 3 items, the code: 5y15hf4w79
Our Company Offer Free Shipping,Free Return&Exchanges For all order, 3-5 business days to Your Door!
We sincerely hope that you will visit our web again and find the product that you prefer.
Sincerely yours
Customer Service
http://www.redbottomshoes-uk.com
com
Nz a little messy [url=http://www.ghdnzstraightenerssales.com/]GHD Straightener NZ[/url] soft? Model with short hair and easy quick appropriately temperament.Cool perfect hair like the model of your ladies just take the treatment of choice, the front just before the wave of explosions and cover design style of the eyelids, hair substantial winds back to develop a three-dimensional model soft [url=http://www.ghdsouthafricanza.com/]GHD South Africa[/url]? visual encounter on both sides of your hair naturally attracted, not to complete an exclusive purchasing this influence is very small to the hair appears to be superior, but a bit messy, but usually not taste Oh! This easy [url=http://www.ghdirelandshops.com/]ghd ireland[/url]? women cooked in a sweet little curly hair.Carved that cross-layer design and style focused, with a perception of a small drawing disheveled hair and a curved tail extended tape style in design and style is distinguished women soft elegant, simple to develop a dynamic, full of air become GHD Straightener ireland? 6wG8YwWP84bQ11-21
http://www.monsterbeatscable.biz/beats-lebron-james-23-headphones-limited-edition-p-219.html James edition studio headphone by dre
http://www.monsterbeatscable.biz/dre-beats-butterfly-by-vivienne-tam-performance-inear-headphone-p-185.html Monster beats butterfly by vivienne tam
http://www.monsterbeatscable.biz/dre-beats-pro-high-performance-professional-headphones-black-p-192.html Monster beats pro black headphone
http://www.monsterbeatscable.biz/dre-beats-pro-high-performance-professional-headphones-white-p-193.html Monster beats pro white headphone
Additions with regards to apparels will be the vests that Moncler offers.
Moncler jackets could be the leading vogue connected with winter months apparel provides the cause. Initial, we could feel available that the early aim of the winter season clothing is usually to continue to keep heated, regardless of how thick they\'re.
Websites with trusted and imitation images side-by-side do the really best work of illustrating these variations. among the best offers are off-centered [url=http://www.replicalouisvuittonbagsale.com./][b]Replica Louis Vuitton Handbags Sale[/b][/url]\'s. trusted [url=http://www.replicalouisvuittonbagsale.com./][b]Replica Louis Vuitton[/b][/url]\'s are commonly based and never moved to some specific ingredient or another. Also, once the [url=http://www.replicalouisvuittonbagsale.com./][b]Replica Louis Vuitton Bags[/b][/url]\'s are straight on each factors in the merchandise, it could be regarded a imitation. When coping with anybody internet source ask much more images to make certain they aren\'t developing using lost images in the product or company within your major site replicalouisvuittonbagsale.com.
Louis Vuitton bags and gear are accepted near to the earth as addressing the level of hand design, structure and position. To this night [url=http://www.replicalouisvuittonbagsale.com./][b]Replica Louis Vuitton Purses[/b][/url] are all hand crafted and properly handled to keep away from fake products. Even when you purchase this company from the split store, it skilled been offered with a very qualified [url=http://www.replicalouisvuittonbagsale.com/lv-cruise-2011-bags-sale-c-21.html][b]LV Cruise 2011 Bags Sale[/b][/url] staff replicalouisvuittonbagsale.com.Louis Vuitton bags and gear are accepted near to the earth as addressing the level of hand design, structure and position. To this night [url=http://www.replicalouisvuittonbagsale.com./][b]Replica Louis Vuitton Purses[/b][/url] are all hand crafted and properly handled to keep away from fake products. Even when you purchase this company from the split store, it skilled been offered with a very qualified [url=http://www.replicalouisvuittonbagsale.com/lv-cruise-2011-bags-sale-c-21.html][b]LV Cruise 2011 Bags Sale[/b][/url] staff replicalouisvuittonbagsale.com.
Websites with trusted and imitation images side-by-side do the really best work of illustrating these variations. among the best offers are off-centered <a href=\"http://www.replicalouisvuittonbagsale.com./\"><strong>Replica Louis Vuitton Handbags Sale</strong></a>\'s. trusted <a href=\"http://www.replicalouisvuittonbagsale.com./\"><strong>Replica Louis Vuitton</strong></a>\'s are commonly based and never moved to some specific ingredient or another. Also, once the <a href=\"http://www.replicalouisvuittonbagsale.com./\"><strong>Replica Louis Vuitton Bags</strong></a>\'s are straight on each factors in the merchandise, it could be regarded a imitation. When coping with anybody internet source ask much more images to make certain they aren\'t developing using lost images in the product or company within your major site replicalouisvuittonbagsale.com.
Louis Vuitton bags and gear are accepted near to the earth as addressing the level of hand design, structure and position. To this night <a href=\"http://www.replicalouisvuittonbagsale.com./\"><strong>Replica Louis Vuitton Purses</strong></a> are all hand crafted and properly handled to keep away from fake products. Even when you purchase this company from the split store, it skilled been offered with a very qualified <a href=\"http://www.replicalouisvuittonbagsale.com/lv-cruise-2011-bags-sale-c-21.html\"><strong>LV Cruise 2011 Bags Sale</strong></a> staff replicalouisvuittonbagsale.com.Louis Vuitton bags and gear are accepted near to the earth as addressing the level of hand design, structure and position. To this night <a href=\"http://www.replicalouisvuittonbagsale.com./\"><strong>Replica Louis Vuitton Purses</strong></a> are all hand crafted and properly handled to keep away from fake products. Even when you purchase this company from the split store, it skilled been offered with a very qualified <a href=\"http://www.replicalouisvuittonbagsale.com/lv-cruise-2011-bags-sale-c-21.html\"><strong>LV Cruise 2011 Bags Sale</strong></a> staff replicalouisvuittonbagsale.com.
new.
<a href=\"http://www.bruinsfanshop.com/zdeno-chara-jersey\">Zdeno Chara Jersey</a>
<a href=\"http://www.bruinsfanshop.com/milan-lucic-jersey\">Milan Lucic Jersey</a>
<a href=\"http://www.bruinsfanshop.com/nathan-horton-jersey\">Nathan Horton Jersey</a>
<a href=\"http://www.bruinsfanshop.com/brad-marchand-jersey\">Brad Marchand Jersey</a>
<a href=\"http://www.bruinsfanshop.com/\">bruins jerseys</a>
<a href=\"http://www.bruinsfanshop.com/blake-wheeler-jersey\">Blake Wheeler Jersey</a>
<a href=\"http://www.bruinsfanshop.com/blank-jersey-c-19\">Blank Jersey</a>
<a href=\"http://www.bruinsfanshop.com/bobby-orr-jersey\">Bobby Orr Jersey</a>
<a href=\"http://www.bruinsfanshop.com/cam-neely-jersey\">Cam Neely Jersey</a>
<a href=\"http://www.bruinsfanshop.com/david-krejci-jersey\">David Krejci Jersey</a>
<a href=\"http://www.bruinsfanshop.com/dennis-wideman-jersey\">Dennis Wideman Jersey</a>
<a href=\"http://www.bruinsfanshop.com/marc-savard-jersey\">Marc Savard Jersey</a>
<a href=\"http://www.bruinsfanshop.com/marco-sturm-jersey\">Marco Sturm Jersey</a>
<a href=\"http://www.bruinsfanshop.com/patrice-bergeron-jersey\">Patrice Bergeron Jersey</a>
<a href=\"http://www.bruinsfanshop.com/phil-esposito-jersey\">Phil Esposito Jersey</a>
<a href=\"http://www.bruinsfanshop.com/phil-kessel-jersey\">Phil Kessel Jersey</a>
<a href=\"http://www.bruinsfanshop.com/ray-bourque-jersey\">Ray Bourque Jersey</a>
<a href=\"http://www.bruinsfanshop.com/terry-o-reilly-jersey\">Terry O\'Reilly Jersey</a>
<a href=\"http://www.bruinsfanshop.com/tyler-seguin-jersey\">Tyler Seguin Jersey</a>
Very informative and cvers almost everything for bloggers. This was the consolidation I was looking for. Thanks !!!!
帖子需很久了!但很实用收藏了
嗯!帖子久了不知道作者是否仍关住
小弟!有一处想请问作者的,本人想使用\"纯真ip库\"不能解析,而且报错了
是否使用其他的网站的IP库不能的,希望提供解决方法了...
感激!!
eval报错那应该是eval的参数里含有不正确的javascript代码,你检查下看
\'\"\'.$record->country_code3.\'\",\'.
\'\"\'.$record->country_name.\'\",\'.
\'\"\'.$GEOIP_REGION_NAME[$record->country_code][$record->region].\'\",\'.
\'\"\'.$record->city.\'\",\'.
$record->latitude.\',\'.$record->longitude.\')\';
是怎么回事 啊?实在不明白了,刚开始学,谢谢
eval函数应该是没错的,具体怎么错我也不是很清楚,你可以用firefox下得firebug插件调试一下代码