Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added street view API (similar to static maps) including tests for st…

…reet view
  • Loading branch information...
commit 0d2eebbe35c26ba5695fba4f9b33ea685d6eec8a 1 parent b4d3d97
@spatical spatical authored
Showing with 103 additions and 0 deletions.
  1. +1 −0  README.md
  2. +33 −0 lib/googlemaps.js
  3. +69 −0 test/streetview-test.js
View
1  README.md
@@ -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:
View
33 lib/googlemaps.js
@@ -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){
View
69 test/streetview-test.js
@@ -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);
Please sign in to comment.
Something went wrong with that request. Please try again.