Permalink
Browse files

fixed broken IP lookup

  • Loading branch information...
1 parent e1c38ad commit b920452afa02e811e98b9c9d63b10476aeb58610 @codepo8 committed Dec 2, 2010
Showing with 11 additions and 7 deletions.
  1. +9 −5 index.html
  2. +2 −2 yqlgeo.js
View
14 index.html
@@ -99,13 +99,17 @@
<h2>Find the user (using the W3C geolocation API and IP as a fallback)</h2>
<pre><code>yqlgeo.get('visitor',function(o){
- alert(o.place.name + ',' + o.place.country.content +
- ' (' + o.place.centroid.latitude + ',' +
- o.place.centroid.longitude + ')'
- );
+ if(o.error){
+ alert('No location found for user :('); // some IPs are not in the DB :(
+ } else {
+ alert(o.place.name + ',' + o.place.country.content +
+ ' (' + o.place.centroid.latitude + ',' +
+ o.place.centroid.longitude + ')'
+ );
+ }
});
</code></pre>
-<button onclick="yqlgeo.get('visitor',function(o){alert(o.place.name + ',' +o.place.country.content + ' ('+o.place.centroid.latitude+','+o.place.centroid.longitude+')')});">Try this out</button>
+<button onclick="yqlgeo.get('visitor',function(o){if(o.error){alert('No location found for user :(');} else {alert(o.place.name + ',' + o.place.country.content + ' (' + o.place.centroid.latitude + ',' +o.place.centroid.longitude + ')');}});">Try this out</button>
<h2>Download the library</h2>
View
4 yqlgeo.js
@@ -58,7 +58,7 @@ var yqlgeo = function(){
function getFromIP(ip){
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'+
+ 'select latitude,longitude from pidgets.geoip'+
' where ip="'+ip+'"))';
load(yql,'yqlgeo.retrieved');
};
@@ -122,7 +122,7 @@ var yqlgeo = function(){
};
function retrieved(o){
- if(o.query.results){
+ if(o.query.results !== null){
callback(o.query.results);
} else {
callback({error:o.query});

0 comments on commit b920452

Please sign in to comment.