Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

all files modified

  • Loading branch information...
commit 868147ff70039a41c139ee12012f043c4466949b 1 parent b535b4c
Adrian Statescu authored
2  YQLGeoLibrary/geo.js
@@ -63,7 +63,7 @@ var yqlgeo = function(){
63 63 };
64 64
65 65 function getFromIP(ip) {
66   - var yql = "select * from geo.places where woeid in (select place.woeid from flickr.places where (lat,lon) in (select Latitude,Longitude from ip.location where ip='"+ip+"'))";
  66 + var yql = "select * from geo.places where woeid in (select place.woeid from flickr.places where (lat,lon) in (select Latitude,Longitude from ip.location where ip='"+ip+"' and key='9fa9c90700b942bbbbbeb19decb33a591140386d2d407d335c46467703002e0b'))";
67 67 if(window.console) {console.log(yql);}
68 68 load(yql,'yqlgeo.retrieved');
69 69 };
2  YQLGeoLibrary/index.html
@@ -56,7 +56,7 @@
56 56 <div class="yui-u" id="info">Loading info...</div>
57 57 </div><!-- and yui-g -->
58 58 </div><!--end bd -->
59   - <div id="ft" role="contentinfo"><p>written by @<a href="http://twitter.com/thinkphp">thinkphp</a> using <a href="http://code.google.com/apis/maps/documentation/staticmaps/">Google Static Maps API V2</a> and <a href="geo.js">YQL Geo Library</a>| <a href="../">version 1</a></p></div>
  59 + <div id="ft" role="contentinfo"><p>written by @<a href="http://twitter.com/thinkphp">thinkphp</a></p></div>
60 60 </div><!-- end doc -->
61 61 <script type="text/javascript" src="geo.js"></script>
62 62 <script type="text/javascript">
153 index.html
... ... @@ -1,95 +1,72 @@
1 1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 2 <html>
3 3 <head>
4   - <title>Getting location from an IP</title>
5   - <link rel="stylesheet" href="http://yui.yahooapis.com/2.7.0/build/reset-fonts-grids/reset-fonts-grids.css" type="text/css">
6   - <link rel="stylesheet" href="http://yui.yahooapis.com/2.7.0/build/base/base.css" type="text/css">
7   - <style type="text/css">
8   - #doc{
9   - background:#f8f8f8;
10   - color:#333;
11   - border:1em solid #f8f8f8;
12   - font-family:georgia,serif;
13   - }
14   - h1{
15   - font-size:180%;
16   - color:#69c;
17   - }
18   - h2{
19   - font-size:150%;
20   - color:#69c;
21   - }
22   - h3{
23   - font-size:140%;
24   - color:#69c;
25   - }
26   - p,li{font-size:130%;}
27   - ul{margin:0 0 0 1.5em;}
28   - li{padding:.2em 0;}
29   - li strong{
30   - width:8em;
31   - float:left;
32   - display:block;
33   - }
34   - #ft {margin-top: 30px;color: #999}
35   - #ft p{
36   - font-size:85%;
37   - text-align:right;
38   - }
39   - #ft p a {color: #69c}
40   - #map{
41   - height:300px;
42   - width:300px;
43   - position:relative;
44   - }
45   - </style>
  4 +<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
  5 +<title></title>
  6 +<style type="text/css">
  7 +html,body{font-family: georgia,arial,verdana,sans-serif;width: 700px;margin-left: 10%}
  8 +div#more a {
  9 + font-weight: bold;
  10 + text-align: center;
  11 + margin: 5px 0;
  12 + display: block;
  13 + background: #4791d9;
  14 + text-decoration: none;
  15 + color: #fff;
  16 + padding: 4px;
  17 + outline: 0;
  18 + border: 0;
  19 + -moz-border-radius: 4px;
  20 + -webkit-border-radius: 4px;
  21 + -o-border-radius: 4px;
  22 + -ms-border-radius: 4px;
  23 + -khtml-border-radius: 4px;
  24 + border-radius: 4px;
  25 + -moz-transition-duration: 0.25s;
  26 + -webkit-transition-duration: 0.25s;
  27 + -o-transition-duration: 0.25s;
  28 + transition-duration: 0.25s;
  29 + -webkit-transition-property: -webkit-transform;
  30 + -moz-transition-property: -moz-transform;
  31 + -o-transition-property: -o-transform;
  32 + transition-property: transform;
  33 + -webkit-transform: scale(1) rotate(0);
  34 + -moz-transform: scale(1) rotate(0);
  35 + -o-transform: scale(1) rotate(0);
  36 + transform: scale(1) rotate(0);
  37 +}
  38 +
  39 +div#more a:hover {
  40 + background: #4791d9;
  41 + text-decoration: none;
  42 + color: #fff;
  43 + -webkit-transform: scale(1.05) rotate(-1deg);
  44 + -moz-transform: scale(1.05) rotate(-1deg);
  45 + -o-transform: scale(1.05) rotate(-1deg);
  46 + transform: scale(1.05) rotate(-1deg);
  47 +}
  48 +
  49 +div#more a:nth-child(2n):hover {
  50 + -webkit-transform: scale(1.05) rotate(1deg);
  51 + -moz-transform: scale(1.05) rotate(1deg);
  52 + -o-transform: scale(1.05) rotate(1deg);
  53 + transform: scale(1.05) rotate(1deg);
  54 +}
  55 +h1{font-size: 320%}
  56 +#ft p a{color: #000}
  57 +</style>
46 58 </head>
47 59 <body>
48   -<div id="doc" class="yui-t7">
49   - <div id="hd" role="banner"><h1>Getting location from IP based on JavaScript</h1></div>
50   - <div id="bd" role="main">
51   - <h2>Map and Info</h2>
52   - <div class="yui-g">
53   - <div class="yui-u first">
54   - <div id="map">Loading map...</div>
55   - </div>
56   - <div class="yui-u" id="info">Loading info...</div>
57   - </div><!-- and yui-g -->
58   - </div><!--end bd -->
59   - <div id="ft" role="contentinfo"><p>written by @<a href="http://twitter.com/thinkphp">thinkphp</a> using <a href="http://www.maxmind.com/">maxmind</a> and <a href="http://code.google.com/apis/maps/documentation/staticmaps/">Google Static Maps API V2</a> | <a href="v2/">v2</a>| <a href="v3/">v3</a>| <a href="YQLGeoLibrary">using YQLGeoLibrary</a></p></div>
60   -</div><!-- end doc -->
61   -<script type="text/javascript" src="http://j.maxmind.com/app/geoip.js"></script>
62   -<script type="text/javascript">
63   -function $(id){ return document.getElementById(id); }
64   -(function(){
65   - var info = $('info');
66   - var lat = geoip_latitude(),
67   - lon = geoip_longitude(),
68   - city = geoip_city(),
69   - region = geoip_region(),
70   - region_name = geoip_region_name(),
71   - postal_code = geoip_postal_code(),
72   - country_name = geoip_country_name(),
73   - country_code = geoip_country_code();
74   - out = '<h3>Information from your IP</h3>'+
75   - '<ul>'+
76   - '<li>Latitude: '+ lat + '</li>'+
77   - '<li>Longitude: '+ lon + '</li>'+
78   - '<li>City: '+ city + '</li>'+
79   - '<li>Region: '+ region + '</li>'+
80   - '<li>Region Name: '+ region_name + '</li>'+
81   - '<li>Postal Code: '+ postal_code + '</li>'+
82   - '<li>Country Name: '+ country_name + '</li>'+
83   - '<li>Country Code: '+ country_code + '</li>'+
84   - '</ul>';
85   - info.innerHTML = out;
86   - var url = 'http://maps.google.com/maps/api/staticmap?center='+
87   - lat+','+lon+'&sensor=false&size=300x300&maptype=roadmap&key='+
88   - 'ABQIAAAAHFKkG2s1GKwMWvhsxH6UGhTsE91L0UkYXwp_YlL0uSAPtCVs5hTWKxoV6BCF8F8RGtpqa4IYPMkbcQ'+
89   - '&markers=color:blue|label:I|'+lat+','+lon+'&visible='+lat+','+lon+'|'+(lat+1)+','+(lon+1);
90   - var map = $('map');
91   - map.innerHTML = '<img src="'+url+'" alt="'+city+'">';
92   - })();
93   -</script>
  60 +<h1>Getting location from IP</h1>
  61 +<div class="container">
  62 + <div id="more">
  63 + <a href="v1/index.html">from your IP using maxmind</a>
  64 + <a href="v2/index.html">from your IP using jsonip.appspot & ip.location</a>
  65 + <a href="v3/index.html">using table geo.places & jsonip.appspot</a>
  66 + <a href="YQLGeoLibrary/index.html">using YQLGeo Library</a>
  67 + </div>
  68 +</div>
  69 +<div id="ft" role="contentinfo"><p>@<a href="http://twitter.com/thinkphp">thinkphp</a> | download on <a href="https://github.com/thinkphp/getting-location-from-ip">GitHub</a></p></div>
94 70 </body>
95 71 </html>
  72 +
95 v1/index.html
... ... @@ -0,0 +1,95 @@
  1 +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2 +<html>
  3 +<head>
  4 + <title>Getting location from your IP using maxmind</title>
  5 + <link rel="stylesheet" href="http://yui.yahooapis.com/2.7.0/build/reset-fonts-grids/reset-fonts-grids.css" type="text/css">
  6 + <link rel="stylesheet" href="http://yui.yahooapis.com/2.7.0/build/base/base.css" type="text/css">
  7 + <style type="text/css">
  8 + #doc{
  9 + background:#f8f8f8;
  10 + color:#333;
  11 + border:1em solid #f8f8f8;
  12 + font-family:georgia,serif;
  13 + }
  14 + h1{
  15 + font-size:180%;
  16 + color:#69c;
  17 + }
  18 + h2{
  19 + font-size:150%;
  20 + color:#69c;
  21 + }
  22 + h3{
  23 + font-size:140%;
  24 + color:#69c;
  25 + }
  26 + p,li{font-size:130%;}
  27 + ul{margin:0 0 0 1.5em;}
  28 + li{padding:.2em 0;}
  29 + li strong{
  30 + width:8em;
  31 + float:left;
  32 + display:block;
  33 + }
  34 + #ft {margin-top: 30px;color: #999}
  35 + #ft p{
  36 + font-size:85%;
  37 + text-align:right;
  38 + }
  39 + #ft p a {color: #69c}
  40 + #map{
  41 + height:300px;
  42 + width:300px;
  43 + position:relative;
  44 + }
  45 + </style>
  46 +</head>
  47 +<body>
  48 +<div id="doc" class="yui-t7">
  49 + <div id="hd" role="banner"><h1>Getting location from your IP based on maxmind</h1></div>
  50 + <div id="bd" role="main">
  51 + <h2>Map and Info</h2>
  52 + <div class="yui-g">
  53 + <div class="yui-u first">
  54 + <div id="map">Loading map...</div>
  55 + </div>
  56 + <div class="yui-u" id="info">Loading info...</div>
  57 + </div><!-- and yui-g -->
  58 + </div><!--end bd -->
  59 + <div id="ft" role="contentinfo"><p>written by @<a href="http://twitter.com/thinkphp">thinkphp</a></p></div>
  60 +</div><!-- end doc -->
  61 +<script type="text/javascript" src="http://j.maxmind.com/app/geoip.js"></script>
  62 +<script type="text/javascript">
  63 +function $(id){ return document.getElementById(id); }
  64 +(function(){
  65 + var info = $('info');
  66 + var lat = geoip_latitude(),
  67 + lon = geoip_longitude(),
  68 + city = geoip_city(),
  69 + region = geoip_region(),
  70 + region_name = geoip_region_name(),
  71 + postal_code = geoip_postal_code(),
  72 + country_name = geoip_country_name(),
  73 + country_code = geoip_country_code();
  74 + out = '<h3>Information from your IP</h3>'+
  75 + '<ul>'+
  76 + '<li>Latitude: '+ lat + '</li>'+
  77 + '<li>Longitude: '+ lon + '</li>'+
  78 + '<li>City: '+ city + '</li>'+
  79 + '<li>Region: '+ region + '</li>'+
  80 + '<li>Region Name: '+ region_name + '</li>'+
  81 + '<li>Postal Code: '+ postal_code + '</li>'+
  82 + '<li>Country Name: '+ country_name + '</li>'+
  83 + '<li>Country Code: '+ country_code + '</li>'+
  84 + '</ul>';
  85 + info.innerHTML = out;
  86 + var url = 'http://maps.google.com/maps/api/staticmap?center='+
  87 + lat+','+lon+'&sensor=false&size=300x300&maptype=roadmap&key='+
  88 + 'ABQIAAAAHFKkG2s1GKwMWvhsxH6UGhTsE91L0UkYXwp_YlL0uSAPtCVs5hTWKxoV6BCF8F8RGtpqa4IYPMkbcQ'+
  89 + '&markers=color:blue|label:I|'+lat+','+lon+'&visible='+lat+','+lon+'|'+(lat+1)+','+(lon+1);
  90 + var map = $('map');
  91 + map.innerHTML = '<img src="'+url+'" alt="'+city+'">';
  92 + })();
  93 +</script>
  94 +</body>
  95 +</html>
9 v2/index.html
... ... @@ -1,7 +1,7 @@
1 1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 2 <html>
3 3 <head>
4   - <title>Getting location from an IP</title>
  4 + <title>Getting location from an IP using jsonapi.appspot</title>
5 5 <link rel="stylesheet" href="http://yui.yahooapis.com/2.7.0/build/reset-fonts-grids/reset-fonts-grids.css" type="text/css">
6 6 <link rel="stylesheet" href="http://yui.yahooapis.com/2.7.0/build/base/base.css" type="text/css">
7 7 <style type="text/css">
@@ -46,7 +46,7 @@
46 46 </head>
47 47 <body>
48 48 <div id="doc" class="yui-t7">
49   - <div id="hd" role="banner"><h1>Getting location from IP based on JavaScript</h1></div>
  49 + <div id="hd" role="banner"><h1>Getting location from IP based on ip.location</h1></div>
50 50 <div id="bd" role="main">
51 51 <h2>Map and Info</h2>
52 52 <div class="yui-g">
@@ -56,7 +56,7 @@
56 56 <div class="yui-u" id="info">Loading info...</div>
57 57 </div><!-- and yui-g -->
58 58 </div><!--end bd -->
59   -<div id="ft" role="contentinfo"><p>written by @<a href="http://twitter.com/thinkphp">thinkphp</a> using <a href="http://jsonip.appspot.com">jsonip.appspot.com</a> and <a href="http://code.google.com/apis/maps/documentation/staticmaps/">Google Static Maps API V2</a> | <a href="../">v1</a>| <a href="../v3/">v3</a></p></div>
  59 +<div id="ft" role="contentinfo"><p>written by @<a href="http://twitter.com/thinkphp">thinkphp</a></p></div>
60 60 </div><!-- end doc -->
61 61 <script type="text/javascript">
62 62 function $(id){ return document.getElementById(id); }
@@ -94,7 +94,8 @@
94 94
95 95 function retrieveIp(o){
96 96 var endpoint = "http://query.yahooapis.com/v1/public/yql?q=";
97   - var yql = "select * from ip.location where ip='"+o.ip+"'";
  97 + var yql = "use 'http://thinkphp.ro/apps/YQL/ip.location2.xml' as ip.location;";
  98 + yql += "select * from ip.location where ip='"+o.ip+"'";
98 99 var url = endpoint + encodeURIComponent(yql) + "&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=seed";
99 100 loadScript(url,function(){if(window.console){console.log(yql);}});
100 101 };
35 v3/index.html
... ... @@ -1,7 +1,7 @@
1 1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 2 <html>
3 3 <head>
4   - <title>Getting location from an IP</title>
  4 + <title>Getting location from an IP using geo.places</title>
5 5 <link rel="stylesheet" href="http://yui.yahooapis.com/2.7.0/build/reset-fonts-grids/reset-fonts-grids.css" type="text/css">
6 6 <link rel="stylesheet" href="http://yui.yahooapis.com/2.7.0/build/base/base.css" type="text/css">
7 7 <style type="text/css">
@@ -46,7 +46,7 @@
46 46 </head>
47 47 <body>
48 48 <div id="doc" class="yui-t7">
49   - <div id="hd" role="banner"><h1>Getting location from IP using JavaScript</h1></div>
  49 + <div id="hd" role="banner"><h1>Getting location from IP using geo.places</h1></div>
50 50 <div id="bd" role="main">
51 51 <h2>Map and Info</h2>
52 52 <div class="yui-g">
@@ -58,7 +58,7 @@
58 58 </div>
59 59 </div><!-- and yui-g -->
60 60 </div><!--end bd -->
61   -<div id="ft" role="contentinfo"><p>written by @<a href="http://twitter.com/thinkphp">thinkphp</a> using <a href="http://jsonip.appspot.com">jsonip.appspot.com</a> and <a href="http://code.google.com/apis/maps/documentation/staticmaps/">Google Static Maps API V2</a> | <a href="../">v1</a>| <a href="../v2/">v2</a></p></div>
  61 +<div id="ft" role="contentinfo"><p>written by @<a href="http://twitter.com/thinkphp">thinkphp</a></p></div>
62 62 </div><!-- end doc -->
63 63 <script type="text/javascript">
64 64 window.yourIP;
@@ -96,17 +96,34 @@
96 96 map.innerHTML = '<img src="'+url+'" alt="'+typecontent+'">';
97 97 };
98 98
99   -function retrieveIp(o){
100   - yourIP = o.ip;
  99 +function go(lat,lng){
101 100 var yql = 'select * from geo.places where woeid in '+
102   - '(select place.woeid from flickr.places where (lat,lon) '+
103   - 'in (select Latitude,Longitude from ip.location where ip="'+o.ip+'"))';
104   - var endpoint = "http://query.yahooapis.com/v1/public/yql?q=";
  101 + '(select place.woeid from flickr.places where lat = "' + lat + '" and lon= "' + lng + '")';
  102 + var endpoint = "http://query.yahooapis.com/v1/public/yql?q=";
105 103 var url = endpoint + encodeURIComponent(yql) + '&format=json&callback=seed&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys';
106 104 if(window.console) {console.log(yql);}
107 105 loadScript(url,function(){});
108 106 };
109 107
  108 +function receivedLatLng(o) {
  109 + var lat = o.query.results.Response.Latitude,
  110 + lng = o.query.results.Response.Longitude;
  111 + go(lat,lng);
  112 +}
  113 +
  114 +function receivedIp(o) {
  115 + yourIP = o.ip;
  116 + retrieveLatLong(o.ip);
  117 +}
  118 +
  119 +function retrieveLatLong(ip) {
  120 + var YQL = 'use "http://thinkphp.ro/apps/YQL/ip.location2.xml" as ip.location; select Latitude,Longitude from ip.location where ip="'+ ip +'"';
  121 + var endpoint = "http://query.yahooapis.com/v1/public/yql?q=";
  122 + var url = endpoint + encodeURIComponent(YQL) + '&format=json&callback=receivedLatLng';
  123 + if(window.console) {console.log(YQL);}
  124 + loadScript(url,function(){});
  125 +}
  126 +
110 127 function loadScript(url, callback){
111 128 var script = document.createElement("script")
112 129 script.type = "text/javascript";
@@ -127,6 +144,6 @@
127 144 document.getElementsByTagName("head")[0].appendChild(script);
128 145 }
129 146 </script>
130   -<script type="text/javascript" src="http://jsonip.appspot.com?callback=retrieveIp"></script>
  147 +<script type="text/javascript" src="http://jsonip.appspot.com?callback=receivedIp"></script>
131 148 </body>
132 149 </html>

0 comments on commit 868147f

Please sign in to comment.
Something went wrong with that request. Please try again.