Skip to content

Commit

Permalink
Changed to use YQL for geoip lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas committed May 4, 2011
1 parent 1ec81f7 commit 97afc52
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 59 deletions.
39 changes: 20 additions & 19 deletions build/gallery-geo/gallery-geo-debug.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
YUI.add('gallery-geo', function(Y) {

/*global YUI*/
//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="209.131.62.113"))

/*
* Copyright (c) 2011 Yahoo! Inc. All rights reserved.
* Written by Nicholas C. Zakas, nczonline.net
*/

var IP_URL = "http://www.geoplugin.net/json.gp?jsoncallback=";

/**
* Geolocation API
Expand Down Expand Up @@ -63,23 +61,26 @@ function getCurrentPositionByAPI(callback, scope){
*/
function getCurrentPositionByGeoIP(callback, scope){

//Try to get by IP address
Y.jsonp(IP_URL, {
format: function(url, proxy){
return url + proxy;
},
Y.YQL("select * from pidgets.geoip", {
on: {
success: function(response){
callback.call(scope, {
success: true,
coords: {
latitude: parseFloat(response.geoplugin_latitude),
longitude: parseFloat(response.geoplugin_longitude),
accuracy: Infinity //TODO: Figure out better value
},
timestamp: +new Date(),
source: "geoplugin"
});
var results;

if (response.error){
callback.call(scope, { success: false });
} else {
results = response.query.results.Result;
callback.call(scope, {
success: true,
coords: {
latitude: parseFloat(results.latitude),
longitude: parseFloat(results.longitude),
accuracy: Infinity //TODO: Figure out better value
},
timestamp: +new Date(),
source: "pidgets.geoip"
});
}
},
failure: function(){
callback.call(scope, { success: false });
Expand Down Expand Up @@ -114,4 +115,4 @@ Y.Geo = {



}, '@VERSION@' ,{requires:['jsonp']});
}, '@VERSION@' ,{requires:['yql']});
2 changes: 1 addition & 1 deletion build/gallery-geo/gallery-geo-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 20 additions & 19 deletions build/gallery-geo/gallery-geo.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
YUI.add('gallery-geo', function(Y) {

/*global YUI*/
//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="209.131.62.113"))

/*
* Copyright (c) 2011 Yahoo! Inc. All rights reserved.
* Written by Nicholas C. Zakas, nczonline.net
*/

var IP_URL = "http://www.geoplugin.net/json.gp?jsoncallback=";

/**
* Geolocation API
Expand Down Expand Up @@ -63,23 +61,26 @@ function getCurrentPositionByAPI(callback, scope){
*/
function getCurrentPositionByGeoIP(callback, scope){

//Try to get by IP address
Y.jsonp(IP_URL, {
format: function(url, proxy){
return url + proxy;
},
Y.YQL("select * from pidgets.geoip", {
on: {
success: function(response){
callback.call(scope, {
success: true,
coords: {
latitude: parseFloat(response.geoplugin_latitude),
longitude: parseFloat(response.geoplugin_longitude),
accuracy: Infinity //TODO: Figure out better value
},
timestamp: +new Date(),
source: "geoplugin"
});
var results;

if (response.error){
callback.call(scope, { success: false });
} else {
results = response.query.results.Result;
callback.call(scope, {
success: true,
coords: {
latitude: parseFloat(results.latitude),
longitude: parseFloat(results.longitude),
accuracy: Infinity //TODO: Figure out better value
},
timestamp: +new Date(),
source: "pidgets.geoip"
});
}
},
failure: function(){
callback.call(scope, { success: false });
Expand Down Expand Up @@ -114,4 +115,4 @@ Y.Geo = {



}, '@VERSION@' ,{requires:['jsonp']});
}, '@VERSION@' ,{requires:['yql']});
3 changes: 2 additions & 1 deletion src/gallery-geo/build.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
builddir=../../../builder/componentbuild
component=gallery-geo
component.jsfiles=geo.js
component.requires=jsonp
component.requires=yql

2 changes: 1 addition & 1 deletion src/gallery-geo/demo/geo.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h1>Geo Tests</h1>
modules: {
'gallery-geo': {
fullpath: '../../../build/gallery-geo/gallery-geo.js',
requires: ["jsonp"],
requires: ["yql"],
optional: [],
supersedes: []
}
Expand Down
37 changes: 19 additions & 18 deletions src/gallery-geo/js/geo.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/*global YUI*/
//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="209.131.62.113"))

/*
* Copyright (c) 2011 Yahoo! Inc. All rights reserved.
* Written by Nicholas C. Zakas, nczonline.net
*/

var IP_URL = "http://www.geoplugin.net/json.gp?jsoncallback=";

/**
* Geolocation API
Expand Down Expand Up @@ -61,23 +59,26 @@ function getCurrentPositionByAPI(callback, scope){
*/
function getCurrentPositionByGeoIP(callback, scope){

//Try to get by IP address
Y.jsonp(IP_URL, {
format: function(url, proxy){
return url + proxy;
},
Y.YQL("select * from pidgets.geoip", {
on: {
success: function(response){
callback.call(scope, {
success: true,
coords: {
latitude: parseFloat(response.geoplugin_latitude),
longitude: parseFloat(response.geoplugin_longitude),
accuracy: Infinity //TODO: Figure out better value
},
timestamp: +new Date(),
source: "geoplugin"
});
var results;

if (response.error){
callback.call(scope, { success: false });
} else {
results = response.query.results.Result;
callback.call(scope, {
success: true,
coords: {
latitude: parseFloat(results.latitude),
longitude: parseFloat(results.longitude),
accuracy: Infinity //TODO: Figure out better value
},
timestamp: +new Date(),
source: "pidgets.geoip"
});
}
},
failure: function(){
callback.call(scope, { success: false });
Expand Down

0 comments on commit 97afc52

Please sign in to comment.