Skip to content

Commit

Permalink
yahoo geocoder + tests fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
xavijam committed Dec 26, 2012
1 parent b9437eb commit 96b16da
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/geo/geocoder.js
Expand Up @@ -31,15 +31,15 @@ cdb.geo.geocoder.YAHOO = {
$.getJSON(protocol + '//query.yahooapis.com/v1/public/yql?q='+encodeURIComponent('SELECT * FROM json WHERE url="http://where.yahooapis.com/geocode?q=' + address + '&appid=' + this.keys.app_id + '&flags=JX"') + '&format=json&callback=?', function(data) { $.getJSON(protocol + '//query.yahooapis.com/v1/public/yql?q='+encodeURIComponent('SELECT * FROM json WHERE url="http://where.yahooapis.com/geocode?q=' + address + '&appid=' + this.keys.app_id + '&flags=JX"') + '&format=json&callback=?', function(data) {


var coordinates = []; var coordinates = [];
if (data && data.query && data.query.results && data.query.results.ResultSet && data.query.results.ResultSet.Found != "0") { if (data && data.query && data.query.results && data.query.results.json && data.query.results.json.ResultSet && data.query.results.json.ResultSet.Found != "0") {


// Could be an array or an object |arg! // Could be an array or an object |arg!
var res; var res;


if (_.isArray(data.query.results.ResultSet.Results)) { if (_.isArray(data.query.results.json.ResultSet.Results)) {
res = data.query.results.ResultSet.Results; res = data.query.results.json.ResultSet.Results;
} else { } else {
res = [data.query.results.ResultSet.Results]; res = [data.query.results.json.ResultSet.Results];
} }


for(var i in res) { for(var i in res) {
Expand Down
12 changes: 6 additions & 6 deletions test/spec/geo/geocoder.spec.js
Expand Up @@ -6,8 +6,8 @@ describe('Geocoder', function() {
it('we should get a direction that exists using YAHOO', function() { it('we should get a direction that exists using YAHOO', function() {
cdb.geo.geocoder.YAHOO.geocode('Madrid, Spain', function(data) { cdb.geo.geocoder.YAHOO.geocode('Madrid, Spain', function(data) {
expect(data.length).toEqual(1); expect(data.length).toEqual(1);
expect(data[0].lat).toEqual('40.420300'); expect(data[0].lat).toEqual('40.4203');
expect(data[0].lon).toEqual('-3.705774'); expect(data[0].lon).toEqual('-3.70577');
expect(data[0].boundingbox).toBeTruthy(); expect(data[0].boundingbox).toBeTruthy();
}); });
}); });
Expand All @@ -21,17 +21,17 @@ describe('Geocoder', function() {
it('we should get a direction that exists using NOKIA', function() { it('we should get a direction that exists using NOKIA', function() {
cdb.geo.geocoder.NOKIA.geocode('Madrid, Spain', function(data) { cdb.geo.geocoder.NOKIA.geocode('Madrid, Spain', function(data) {
expect(data.length).toEqual(1); expect(data.length).toEqual(1);
expect(data[0].lat).toEqual(parseFloat('40.4203')); expect(data[0].lat).toEqual(40.420300);
expect(data[0].lon).toEqual(parseFloat('-3.70577')); expect(data[0].lon).toEqual(-3.70577);
expect(data[0].boundingbox).toBeTruthy(); expect(data[0].boundingbox).toBeTruthy();
}); });
}); });


it('we should get a direction with # character using NOKIA', function() { it('we should get a direction with # character using NOKIA', function() {
cdb.geo.geocoder.NOKIA.geocode('# Mexico', function(data) { cdb.geo.geocoder.NOKIA.geocode('# Mexico', function(data) {
expect(data.length).toEqual(1); expect(data.length).toEqual(1);
expect(data[0].lat).toEqual('19.4321'); expect(data[0].lat).toEqual(19.4321);
expect(data[0].lon).toEqual('-99.1331'); expect(data[0].lon).toEqual(-99.1331);
}); });
}); });


Expand Down

0 comments on commit 96b16da

Please sign in to comment.