A simple way to query the Google Maps API from Node.js
Link to google API https://developers.google.com/maps/documentation/javascript/3.exp/reference
npm install googlemaps
APIs implemented:
APIs Not implemented:
- Map | MapOptions | MapTypeId
-
Overlays
-
Controls
-
- BicyclingLayer
- FusionTablesLayer
- FusionTablesLayerOptions
- FusionTablesQuery
- FusionTablesStyle
- FusionTablesHeatmap
- FusionTablesMarkerOptions
- FusionTablesPolygonOptions
- FusionTablesPolylineOptions
- FusionTablesMouseEvent
- FusionTablesCell
- KmlLayer
- KmlLayerOptions
- KmlLayerMetadata
- KmlLayerStatus
- KmlMouseEvent
- KmlFeatureData
- KmlAuthor
- TrafficLayer
- TransitLayer
TODO: ###Map
###Controls
- MapTypeControlOptions
- MapTypeControlStyle
- OverviewMapControlOptions
- PanControlOptions
- RotateControlOptions
- ScaleControlOptions
- ScaleControlStyle
- StreetViewControlOptions
- ZoomControlOptions
- ZoomControlStyle
- ControlPosition
###Overlays
- Marker
- MarkerOptions
- Icon
- MarkerShape
- Symbol
- SymbolPath
- Animation
- InfoWindow
- InfoWindowOptions
- Polyline
- PolylineOptions
- IconSequence
- Polygon
- PolygonOptions
- PolyMouseEvent
- Rectangle
- RectangleOptions
- Circle
- CircleOptions
- StrokePosition
- GroundOverlay
- GroundOverlayOptions
- OverlayView
- MapPanes
- MapCanvasProjection
###Services
- Geocoder
- [GeocoderRequest]
- [GeocoderStatus]
- [GeocoderResult]
- [GeocoderAddressComponent]
- [GeocoderGeometry]
- [GeocoderLocationType]
- [DirectionsRenderer]
- [DirectionsRendererOptions]
- [DirectionsService]
- [DirectionsRequest]
- [TravelMode]
- [UnitSystem]
- [TransitOptions]
- [DirectionsWaypoint]
- [DirectionsStatus]
- [DirectionsResult]
- [DirectionsRoute]
- [DirectionsLeg]
- [DirectionsStep]
- [Distance]
- [Duration]
- [Time]
- [TransitDetails]
- [TransitStop]
- [TransitLine]
- [TransitAgency]
- [TransitVehicle]
- [VehicleType]
- [ElevationService]
- [LocationElevationRequest]
- [PathElevationRequest]
- [ElevationResult]
- [ElevationStatus]
- [MaxZoomService]
- [MaxZoomResult]
- [MaxZoomStatus]
- [DistanceMatrixService]
- [DistanceMatrixRequest]
- [DistanceMatrixResponse]
- [DistanceMatrixResponseRow]
- [DistanceMatrixResponseElement]
- [DistanceMatrixStatus]
- [DistanceMatrixElementStatus]
###Map Types
- MapType
- [MapTypeRegistry]
- [Projection]
- [ImageMapType]
- [ImageMapTypeOptions]
- [StyledMapType]
- [StyledMapTypeOptions]
- [MapTypeStyle]
- [MapTypeStyleFeatureType]
- [MapTypeStyleElementType]
- [MapTypeStyler]
###Layers
- [BicyclingLayer]
- [FusionTablesLayer]
- [FusionTablesLayerOptions]
- [FusionTablesQuery]
- [FusionTablesStyle]
- [FusionTablesHeatmap]
- [FusionTablesMarkerOptions]
- [FusionTablesPolygonOptions]
- [FusionTablesPolylineOptions]
- [FusionTablesMouseEvent]
- [FusionTablesCell]
- [KmlLayer]
- [KmlLayerOptions]
- [KmlLayerMetadata]
- [KmlLayerStatus]
- [KmlMouseEvent]
- [KmlFeatureData]
- [KmlAuthor]
- [TrafficLayer]
- [TransitLayer]
###Street View
- StreetViewPanorama
- [StreetViewPanoramaOptions]
- [StreetViewAddressControlOptions]
- [StreetViewLink]
- [StreetViewPov]
- [StreetViewPanoramaData]
- [StreetViewLocation]
- [StreetViewTileData]
- [StreetViewService]
- [StreetViewStatus]
- [StreetViewCoverageLayer]
###Events
- MapsEventListener
- [event]
- [MouseEvent]
###Base
- [LatLng]
- [LatLngBounds]
- [Point]
- [Size]
###MVC
- [MVCObject]
- [MVCArray]
###Geometry Library
- [encoding]
- [spherical]
- [poly]
###AdSense Library
- [AdUnit]
- [AdUnitOptions]
- [AdFormat]
###Panoramio Library
- [PanoramioLayer]
- [PanoramioLayerOptions]
- [PanoramioFeature]
- [PanoramioMouseEvent]
###Places Library
- [Autocomplete]
- [AutocompleteOptions]
- [AutocompletePrediction]
- [PredictionTerm]
- [PredictionSubstring]
- [AutocompleteService]
- [AutocompletionRequest]
- [ComponentRestrictions]
- [PlaceAspectRating]
- [PlaceDetailsRequest]
- [PlaceGeometry]
- PlacePhoto
- [PhotoOptions]
- [PlaceResult]
- [PlaceReview]
- [PlaceSearchPagination]
- [PlaceSearchRequest]
- [PlacesService]
- [PlacesServiceStatus]
- [QueryAutocompletePrediction]
- [QueryAutocompletionRequest]
- [RadarSearchRequest]
- [RankBy]
- [SearchBox]
- [SearchBoxOptions]
- [TextSearchRequest]
###Drawing Library
- [DrawingManager]
- [DrawingManagerOptions]
- [DrawingControlOptions]
- [OverlayCompleteEvent]
- [OverlayType]
###Weather Library
- CloudLayer
- [WeatherLayer]
- [WeatherLayerOptions]
- [TemperatureUnit]
- [WindSpeedUnit]
- [LabelColor]
- [WeatherMouseEvent]
- [WeatherFeature]
- [WeatherConditions]
- [WeatherForecast]
###Visualization Library
- MapsEngineLayer
- [MapsEngineLayerOptions]
- [MapsEngineLayerProperties]
- [MapsEngineMouseEvent]
- [MapsEngineStatus]
- [DynamicMapsEngineLayer]
- [DynamicMapsEngineLayerOptions]
- [DynamicMapsEngineMouseEvent]
- [FeatureStyle]
- [HeatmapLayer]
- [HeatmapLayerOptions]
- [WeightedLocation]
- [DemographicsLayer]
- [DemographicsLayerOptions]
- [DemographicsQuery]
- [DemographicsStyle]
- [DemographicsPolygonOptions]
- [DemographicsPropertyStyle]
Install get working and make a list of all options not currently working and ad in the new features. 3.13experimenal.
- Tests for everything (using vows)
var gm = require('googlemaps');
var util = require('util');
gm.reverseGeocode('41.850033,-87.6500523', function(err, data){
util.puts(JSON.stringify(data));
});
gm.reverseGeocode(gm.checkAndConvertPoint([41.850033, -87.6500523]), function(err, data){
util.puts(JSON.stringify(data));
});
Both examples print: {"status":"OK","results":[{"types":["postal_code"],"formatted_address":"Chicago, IL 60695, USA"...
For the Static Maps API, you can pass in all the required parameters as well as markers, styles, and paths using the formats outlined below.
markers = [
{ 'location': '300 W Main St Lock Haven, PA' },
{ 'location': '444 W Main St Lock Haven, PA',
'color': 'red',
'label': 'A',
'shadow': 'false',
'icon' : 'http://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=cafe%7C996600'
}
]
styles = [
{ 'feature': 'road', 'element': 'all', 'rules':
{ 'hue': '0x00ff00' }
}
]
paths = [
{ 'color': '0x0000ff', 'weight': '5', 'points':
[ '41.139817,-77.454439', '41.138621,-77.451596' ]
}
]
util.puts(gm.staticMap('444 W Main St Lock Haven PA', 15, '500x400', false, false, 'roadmap', markers, styles, paths));
By giving gm.staticMap an optional callback, you can retreive the static map PNG data:
util.puts(gm.staticMap('444 W Main St Lock Haven PA', 15, '500x400', function(err, data){
require('fs').writeFileSync('test_map.png', data, 'binary');
}, false, 'roadmap', markers, styles, paths));
You will get a map like:
To set the configuration you call gm.config(key, value) or gm.config({key: value, .....})
proxy - set a proxy for http requests
stagger-time - defaults to 200ms - stagger async call times when multiple requests are required
encode-polylines - defaults to true - encodes polylines to the shorter Google format.
google-client-id - used for setting business specific parameters
google-private-key- used for setting business specific parameters
All the googlemaps functions follow this scheme: function(required, callback, optional)
All callbacks are expected to follow: function(error, results) Where the error returned is an Error object.
Please refer to the code, tests and the Google Maps API docs for further usage information.