Google Geocoding Rest API

A rest API flow that wraps the Google Geocoding API.

This flow makes use of the Google Web Nodes (https://github.com/node-red/node-red-web-nodes/tree/master/google)

Prerequisites

Usage

The flow will create an HTTP endpoint for both types of Google Geocoding requests. You can make changes to the Google Geocoding node's configuration if you would like to include any information ahead of time, like API key for instance. All properties taken by the Google Geocoding node can be passed as msg level parameters. The Google Geocoding node is heavily documented, and details about possible parameters can be acquired via the info tab. All errors that occur will be relayed back to the user via the catch node.

[{"id":"703b17e5.8fc4e8","type":"swagger-doc","summary":"Geocoding by Coordinates","description":"The Geocoding endpoint performs a request against the Google Geocoding API. This will convert a set of coordinate points into a human-readable address.","tags":"GoogleGeocoding","consumes":"application/json","produces":"application/json","parameters":[{"name":"lat","in":"query","description":"Latitude point to be sent to Google in order to be converted to a human-readable address.","required":true,"type":"string","format":"double"},{"name":"lon","in":"query","description":"Longitude point to be sent to Google in order to be converted to a human-readable address.","required":true,"type":"number","format":"double"},{"name":"key","in":"query","description":"Your application's API key. This key identifies your application for purposes of quota management. (https://code.google.com/apis/console/)\"","required":false,"type":"string"},{"name":"bounds","in":"query","description":"The bounding box of the viewport within which to bias geocode results more prominently. This parameter will only influence, not fully restrict, results from the geocoder.","required":false,"type":"string"},{"name":"language","in":"query","description":"The language in which to return results.","required":false,"type":"string"},{"name":"region","in":"query","description":"The region code, specified as a ccTLD (\\\"top-level domain\\\") two-character value. This parameter will only influence, not fully restrict, results from the geocoder.","required":false,"type":"string"},{"name":"components","in":"query","description":"The component filters, separated by a pipe (|). Each component filter consists of a component:value pair and will fully restrict the results from the geocoder.","required":false,"type":"string"}],"responses":{"200":{"description":"The address that corresponds to the given coordinate pair, as provided by Google.","schema":{"properties":{"status":{"type":"string"},"address":{"type":"string"}}}},"400":{"description":"Your request was malformed, either by missing or incorrect parameters.","schema":{"properties":{"status":{"type":"string"},"error":{"type":"string"}}}},"401":{"description":"You provided an API Key that is invalid, or is not authorized to use the Google Geocoding API.","schema":{"properties":{"status":{"type":"string"},"error":{"type":"string"}}}},"429":{"description":"You have used the daily allotment of Google Geocoding requests for the provided API Key.","schema":{"properties":{"status":{"type":"string"},"error":{"type":"string"}}}},"500":{"description":"An unknown error occurred. Please try your request again.","schema":{"properties":{"status":{"type":"string"},"error":{"type":"string"}}}}},"deprecated":false},{"id":"14a2d314.eb5d2d","type":"swagger-doc","summary":"Geocoding by Address","description":"The Geocoding endpoint performs a request against the Google Geocoding API. This will convert an address into a set of lat/lon coordinate points.","tags":"GoogleGeocoding","consumes":"application/json","produces":"application/json","parameters":[{"name":"address","in":"query","description":"Address to be sent to Google in order to be converted to a latitude/longitude coordinate set.","required":true,"type":"string"},{"name":"key","in":"query","description":"Your application's API key. This key identifies your application for purposes of quota management. (https://code.google.com/apis/console/)","required":false,"type":"string"},{"name":"bounds","in":"query","description":"The bounding box of the viewport within which to bias geocode results more prominently. This parameter will only influence, not fully restrict, results from the geocoder.","required":false,"type":"string"},{"name":"language","in":"query","description":"The language in which to return results.","required":false,"type":"string"},{"name":"region","in":"query","description":"The region code, specified as a ccTLD (\\\"top-level domain\\\") two-character value. This parameter will only influence, not fully restrict, results from the geocoder.","required":false,"type":"string"},{"name":"components","in":"query","description":"The component filters, separated by a pipe (|). Each component filter consists of a component:value pair and will fully restrict the results from the geocoder.","required":false,"type":"string"}],"responses":{"200":{"description":"The coordinate pair that corresponds to the given address, as provided by Google.","schema":{"properties":{"status":{"type":"string"},"lat":{"type":"number","format":"double"},"lon":{"type":"number","format":"double"}}}},"400":{"description":"Your request was malformed, either by missing or incorrect parameters.","schema":{"properties":{"status":{"type":"string"},"error":{"type":"string"}}}},"401":{"description":"You provided an API Key that is invalid, or is not authorized to use the Google Geocoding API.","schema":{"properties":{"status":{"type":"string"},"error":{"type":"string"}}}},"429":{"description":"You have used the daily allotment of Google Geocoding requests for the provided API Key.","schema":{"properties":{"status":{"type":"string"},"error":{"type":"string"}}}},"500":{"description":"An unknown error occurred. Please try your request again.","schema":{"properties":{"status":{"type":"string"},"error":{"type":"string"}}}}},"deprecated":false},{"id":"98f67d7.f67098","type":"catch","name":"","x":135,"y":209,"z":"ef8b8f86.10747","wires":[["74680c71.8b97f4"]]},{"id":"74680c71.8b97f4","type":"function","name":"Move error to http-out","func":"var error = msg._error;\nmsg.payload = error;\nif(error){\n    msg.statusCode = error.code || 500;\n} else{\n    msg.statusCode = 500;\n}\nreturn msg;","outputs":1,"valid":true,"x":360,"y":209,"z":"ef8b8f86.10747","wires":[["7751e4ed.88ae1c"]]},{"id":"7751e4ed.88ae1c","type":"http response","name":"","x":550,"y":209,"z":"ef8b8f86.10747","wires":[]},{"id":"8ad43c39.752bc","type":"http response","name":"","x":1213,"y":79,"z":"ef8b8f86.10747","wires":[]},{"id":"bfeb4484.4014b8","type":"http in","name":"","url":"/geocoding/address","method":"get","swaggerDoc":"14a2d314.eb5d2d","x":178,"y":56,"z":"ef8b8f86.10747","wires":[["df2b7c1d.20d48"]]},{"id":"df2b7c1d.20d48","type":"function","name":"Move Query Params to Msg","func":"msg.location = {};\nif(msg.req.query.address){\n\tmsg.location.address = msg.req.query.address;\n}\nif(msg.req.query.lat || msg.req.query.lon){\n\tmsg.location.lat = msg.req.query.lat;\n\tmsg.location.lon = msg.req.query.lon;\n}\nif(msg.req.query.key){\n\tmsg.key = msg.req.query.key;\n}\nif(msg.req.query.bounds){\n\tmsg.bounds = msg.req.query.bounds;\n}\nif(msg.req.query.language){\n\tmsg.language = msg.req.query.language;\n}\nif(msg.req.query.region){\n\tmsg.region = msg.req.query.region;\n}\nif(msg.req.query.components){\n\tmsg.components = msg.req.query.components;\n}\nreturn msg;","outputs":1,"valid":true,"x":449,"y":56,"z":"ef8b8f86.10747","wires":[["db465e8b.24b9a"]]},{"id":"db465e8b.24b9a","type":"google geocoding","name":"","geocodeBy":"address","address":"","lat":"","lon":"","googleAPI":"","bounds":"","language":"","region":"","components":"","x":717,"y":56,"z":"ef8b8f86.10747","wires":[["44519ccb.bbae64"]]},{"id":"99793d06.6686c","type":"google geocoding","name":"","geocodeBy":"coordinates","address":"","lat":"","lon":"","googleAPI":"","bounds":"","language":"","region":"","components":"","x":727,"y":115,"z":"ef8b8f86.10747","wires":[["44519ccb.bbae64"]]},{"id":"44519ccb.bbae64","type":"function","name":"Convert msg to http out","func":"msg.payload.status = msg.status;\nif(msg.html_attributions){\n\tmsg.payload.html_attributions = msg.html_attributions;\n}\nreturn msg;","outputs":1,"valid":true,"x":1003,"y":79,"z":"ef8b8f86.10747","wires":[["8ad43c39.752bc"]]},{"id":"ab07a1af.54f86","type":"http in","name":"","url":"/geocoding/coordinates","method":"get","swaggerDoc":"703b17e5.8fc4e8","x":178,"y":115,"z":"ef8b8f86.10747","wires":[["79cd1939.8632e8"]]},{"id":"79cd1939.8632e8","type":"function","name":"Move Query Params to Msg","func":"msg.location = {};\nif(msg.req.query.address){\n\tmsg.location.address = msg.req.query.address;\n}\nif(msg.req.query.lat || msg.req.query.lon){\n\tmsg.location.lat = msg.req.query.lat;\n\tmsg.location.lon = msg.req.query.lon;\n}\nif(msg.req.query.key){\n\tmsg.key = msg.req.query.key;\n}\nif(msg.req.query.bounds){\n\tmsg.bounds = msg.req.query.bounds;\n}\nif(msg.req.query.language){\n\tmsg.language = msg.req.query.language;\n}\nif(msg.req.query.region){\n\tmsg.region = msg.req.query.region;\n}\nif(msg.req.query.components){\n\tmsg.components = msg.req.query.components;\n}\nreturn msg;","outputs":1,"valid":true,"x":451,"y":115,"z":"ef8b8f86.10747","wires":[["99793d06.6686c"]]}]

Flow Info

Created 9 years, 5 months ago
Updated 8 years, 9 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • catch (x1)
  • function (x4)
  • http in (x2)
  • http response (x2)
Other

Tags

  • Google
  • Geocoding
  • GoogleGeocoding
  • GoogleMaps
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option