Skip to content

Commit

Permalink
Added street view API (similar to static maps) including tests for st…
Browse files Browse the repository at this point in the history
…reet view
  • Loading branch information
spatical committed Mar 12, 2012
1 parent b4d3d97 commit 0d2eebb
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ APIs implemented:
* [Place Details](https://code.google.com/apis/maps/documentation/places/#PlaceDetails)
* [Distance Matrix](http://code.google.com/apis/maps/documentation/distancematrix/)
* [Static Maps](http://code.google.com/apis/maps/documentation/staticmaps/)
* [Street View](http://code.google.com/apis/maps/documentation/streetview/)

TODO:

Expand Down
33 changes: 33 additions & 0 deletions lib/googlemaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,39 @@ exports.staticMap = function(center , zoom , size , callback , sensor ,
return 'http://maps.googleapis.com' + path;
};

// http://code.google.com/apis/maps/documentation/streetview
exports.streetView = function(size , location , callback , sensor ,
heading , fov , pitch){
var args = {
'size': size,
'location': location
};
if(heading){
heading = parseInt(heading);
if( heading >= 0 && heading <= 360)
args.heading = heading;
}
if(fov){
fov = parseInt(fov);
if( fov >= 0 && fov <= 120)
args.fov = fov;
}
if(pitch){
pitch = parseInt(pitch);
if( pitch >= -90 && pitch <= 90)
args.pitch = pitch;
}
args.sensor = sensor || 'false';

var path = '/maps/api/streetview?' + qs.stringify(args);

if( typeof( callback ) === 'function' ){
makeRequest( path , false , callback , 'binary' );
}

return 'http://maps.googleapis.com' + path;
};

// Helper function to check and convert an array of points, be it strings/numbers/etc
// into the format used by Google Maps for representing lists of latitude/longitude pairs
exports.checkAndConvertArrayOfPoints = function(input){
Expand Down
69 changes: 69 additions & 0 deletions test/streetview-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
var vows = require('vows'),
assert = require('assert'),
crypto = require('crypto'),
gm = require('../lib/googlemaps');

vows.describe('streetview').addBatch({
'Street View': {

'Simple Parameters URL': {
topic: function(options){
return gm.streetView('600x300', '56.960654,-2.201815', false);
},
'returns the expected street view URL': function(result){
assert.equal(result , "http://maps.googleapis.com/maps/api/streetview?size=600x300&location=56.960654%2C-2.201815&sensor=false");
}
},

'Simple Parameters Image data (jpeg)': {
topic: function(options){
gm.streetView('600x300', '56.960654,-2.201815', this.callback);
},
'returns the expected static map Image data': function(err, data){
var md5 = crypto.createHash('md5');
md5.update(data);
assert.equal(md5.digest('hex') , 'a355992522bc7d640ba605268e703e37');
}
},

'With Optonal Parameters URL': {
topic: function(options){
return gm.streetView('600x300', '56.960654,-2.201815', false, false, "250", "90", "-10");
},
'returns the expected street view URL': function(result){
assert.equal(result , "http://maps.googleapis.com/maps/api/streetview?size=600x300&location=56.960654%2C-2.201815&heading=250&fov=90&pitch=-10&sensor=false");
}
},

'With Optonal Parameters Image data (jpeg)': {
topic: function(options){
gm.streetView('600x300', '56.960654,-2.201815', this.callback, false, "250", "90", "-10");
},
'returns the expected static map Image data': function(err, data){
var md5 = crypto.createHash('md5');
md5.update(data);
assert.equal(md5.digest('hex') , 'f408a7709312394a9ed88ad33cee6145');
}
},

'With invalid Parameters URL': {
topic: function(options){
return gm.streetView('600x300', '56.960654,-2.201815', false, false, "9999", "9999", "9999");
},
'returns the expected street view URL': function(result){
assert.equal(result , "http://maps.googleapis.com/maps/api/streetview?size=600x300&location=56.960654%2C-2.201815&sensor=false");
}
},

'With invalid Parameters Image data (jpeg)': {
topic: function(options){
gm.streetView('600x300', '56.960654,-2.201815', this.callback, false, "9999", "9999", "9999");
},
'returns the expected static map Image data': function(err, data){
var md5 = crypto.createHash('md5');
md5.update(data);
assert.equal(md5.digest('hex') , 'a355992522bc7d640ba605268e703e37');
}
}
}
}).export(module);

0 comments on commit 0d2eebb

Please sign in to comment.