Skip to content

Commit

Permalink
Changes to README
Browse files Browse the repository at this point in the history
Fixed typos in googlemaps.js
  • Loading branch information
moshen committed Aug 17, 2010
1 parent c090b37 commit 06a612e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
13 changes: 10 additions & 3 deletions README.md
Expand Up @@ -10,20 +10,27 @@ APIs implemented:
* Directions
* Elevation

TODO:

* Places
* Static Maps
* Tests for everything
* create npm package

# Usage
var gm = require('googlemaps');
var sys = require('sys');

gm.reverseGeocode('41.850033,-87.6500523', function(data){
gm.reverseGeocode('41.850033,-87.6500523', function(err, data){
sys.puts(JSON.stringify(data));
});

gm.reverseGeocode(gm.checkAndConvertPoint([41.850033, -87.6500523]), function(data){
gm.reverseGeocode(gm.checkAndConvertPoint([41.850033, -87.6500523]), function(err, data){
sys.puts(JSON.stringify(data));
});

Both examples print:
{"status":"OK","results":[{"types":["postal_code"],"formatted_address":"Chicago, IL 60695, USA"...

Please refer to the code and the [Google Maps API docs](http://code.google.com/apis/maps/documentation/webservices/index.html) for further information on the required input parameters.
Please refer to the code, tests and the [Google Maps API docs](http://code.google.com/apis/maps/documentation/webservices/index.html) for further usage information.

28 changes: 18 additions & 10 deletions lib/googlemaps.js
Expand Up @@ -2,10 +2,13 @@ var qs = require('querystring'),
http = require('http');

// http://code.google.com/apis/maps/documentation/geocoding/
exports.geocode = function(address , callback , sensor){
exports.geocode = function(address , callback , sensor , bounds , region , language){
args = {
'address': address
}
if(bounds){ args.bounds = bounds; }
if(region){ args.region = region; }
if(language){ args.language = language; }
args.sensor = sensor || 'false';

var path = '/maps/api/geocode/json?' + qs.stringify(args);
Expand All @@ -14,12 +17,10 @@ exports.geocode = function(address , callback , sensor){
}

// http://code.google.com/apis/maps/documentation/geocoding/#ReverseGeocoding
exports.reverseGeocode = function(latlng , callback , sensor , bounds , region , language ){
exports.reverseGeocode = function(latlng , callback , sensor , language ){
var args = {
'latlng': latlng
}
if(bounds){ args.bounds = bounds; }
if(region){ args.region = region; }
if(language){ args.language = language; }
args.sensor = sensor || 'false';

Expand All @@ -37,7 +38,7 @@ exports.directions = function(origin , destination , callback , sensor , mode ,
args.sensor = sensor || 'false';
if(mode){ args.mode = mode; }
if(waypoints){ args.waypoints = waypoints; }
if(aleternatives){ args.aleternatives = alternatives; }
if(alternatives){ args.alternatives = alternatives; }
if(avoid){ args.avoid = avoid; }
if(units){ args.units = units; }
if(language){ args.language = language; }
Expand Down Expand Up @@ -89,7 +90,7 @@ exports.checkAndConvertArrayOfPoints = function(input){
case 'string':
return input;
}
throw("Unrecognized input: checkAndConvertArrayOfPoints accepts Arrays and Strings");
throw(new Error("Unrecognized input: checkAndConvertArrayOfPoints accepts Arrays and Strings"));
}

// Helper function to check and convert an points, be it strings/arrays of numbers/etc
Expand All @@ -104,13 +105,13 @@ exports.checkAndConvertPoint = function(input){
case 'string':
return input;
}
throw("Unrecognized input: checkAndConvertPoint accepts Arrays of Numbers and Strings");
throw(new Error("Unrecognized input: checkAndConvertPoint accepts Arrays of Numbers and Strings"));
}

// Wraps the callback function to convert the output to a javascript object
var returnObjectFromJSON = function(callback){
return function(jsonString){
callback(JSON.parse(jsonString));
return function(err, jsonString){
callback(err , JSON.parse(jsonString));
}
}

Expand All @@ -130,7 +131,14 @@ var makeRequest = function(path , callback){
data += chunk;
});
response.on('end', function () {
callback(data);
if(response.statusCode == 200){
callback(null, data);
}else{
callback(new Error('Response Status code: ' + response.statusCode), data);
}
});
response.on('error', function (error) {
callback(error , data);
});
});
request.end();
Expand Down

0 comments on commit 06a612e

Please sign in to comment.