Permalink
Browse files

made grade so it can be negative

  • Loading branch information...
1 parent 7c66e57 commit 66d87ff8d6ce9b9b63d71806a6df3e18447505fa @regality regality committed Apr 17, 2012
Showing with 13 additions and 28 deletions.
  1. +11 −26 geolib.js
  2. +1 −1 package.json
  3. +1 −1 tests/geolib.test.html
View
@@ -14,8 +14,11 @@
var radius = 6378137; // Earth radius
var sexagesimalPattern = /^([0-9]{1,3}\s*([0-9]{1,3})'\s*(([0-9]{1,3}(\.([0-9]{1,2}))?)"\s*)?([NEOSW]?)$/;
- var google_client_id;
- var google_private_key;
+ var googleClientId;
+ var googlePrivateKey;
+ if (typeof window.navigator === 'undefined') {
+ var gm = require('googlemaps');
+ }
var geolib = {
@@ -500,7 +503,6 @@
} else { // default is rhumb line bearing
var bearing = geolib.getRhumbLineBearing(originLL, destLL);
}
- console.log(Math.round(bearing/22.5))
switch(Math.round(bearing/22.5)) {
case 1:
@@ -622,9 +624,8 @@
*
* @return Array [{lat:#lat, lng:#lng, elev:#elev},....]}
*/
- setBusinessSpecificParameters: function(client_id, private_key){
- google_client_id = client_id;
- google_private_key = private_key;
+ setBusinessSpecificParameters: function(clientId, privateKey){
+ gm.setBusinessSpecificParameters(clientId, privateKey);
},
/**
@@ -675,21 +676,20 @@
}
},
- getElevationServer: function(coords, cb){
+ getElevationServer: function(coords, cb) {
try {
if (coords.length == 0) {
return cb(null, null);
}
if (coords.length == 1) {
return cb(new Error("Geolib: getElevation requires at least 2 points."));
}
- var gm = require('googlemaps');
var path = [];
var keys = geolib.getKeys(coords[0]);
coords[0]
var latitude = keys.latitude;
var longitude = keys.longitude;
- for(var i = 0; i < coords.length; i++) {
+ for (var i = 0; i < coords.length; i++) {
path.push(geolib.useDecimal(coords[i][latitude]) + ',' +
geolib.useDecimal(coords[i][longitude]));
}
@@ -699,21 +699,6 @@
} catch (e) {
return cb(e);
}
- var gm = require('googlemaps');
- if(google_client_id && google_private_key){
- gm.setBusinessSpecificParameters(google_client_id, google_private_key);
- }
- var path = [];
- var keys = geolib.getKeys(coords[0]);
- var latitude = keys.latitude;
- var longitude = keys.longitude;
- for(var i = 0; i < coords.length; i++) {
- path.push(geolib.useDecimal(coords[i][latitude]) + ',' +
- geolib.useDecimal(coords[i][longitude]));
- }
- gm.elevationFromPath(path.join('|'), path.length, function(err, results) {
- geolib.elevationHandler(results.results, results.status, coords, keys, cb)
- });
},
elevationHandler: function(results, status, coords, keys, cb){
@@ -730,7 +715,7 @@
}
cb(null, latsLngsElevs);
} else {
- cb(new Error("Geolib: Could not get elevation using Google's API"), elevationResult.status);
+ cb(new Error("Geolib: Could not get elevation using Google's API: Status: " + status));
}
},
@@ -743,7 +728,7 @@
getGrade: function(coords, digits) {
var keys = geolib.getKeys(coords[0]);
var elevation = keys.elevation;
- var rise = Math.abs(coords[coords.length-1][elevation] - coords[0][elevation]);
+ var rise = coords[coords.length-1][elevation] - coords[0][elevation];
var run = geolib.getPathLength(coords);
var grade = (rise/run)*100;
if (typeof digits === "number") {
View
@@ -13,7 +13,7 @@
"url" : "http://github.com/manuelbieh/geolib.git"
},
"dependencies": {
- "googlemaps": ">= 0.1.6"
+ "googlemaps": "git+ssh://git@github.com:ifit/node-googlemaps.git"
},
"devDependencies": {
"mocha": "*"
View
@@ -157,7 +157,7 @@
equal(grade, 51.4, "grade should be 51.4");
grade = geolib.getGrade(coords2, 1);
- equal(grade, 31.9, "grade should be 31.9");
+ equal(grade, -32, "grade should be -32");
});
test("Testing elevation gain and loss: getTotalElevationGainAndLoss()", function() {

0 comments on commit 66d87ff

Please sign in to comment.