Tweet to latitude / longitude coordinates

This is a very basic rough/ready flow for taking a twitter input searching a hashtag and then searching the location the tweet came from to return the latitude/longitude co-ordinates.

You could use this to do sentiment analysis linked to websockets so you can have a live google map view of tweet emotions!

I am more than happy to take feedback on this as it is VERY rough.

The flow contains both openstreetmap and google api implementation, take your pick which you want to use.

[{"id":"75ee0f21.8a11f","type":"http request","name":"","method":"GET","url":"","x":444,"y":474,"z":"d05d9cdf.2fa26","wires":[["fa5bd875.05a428"]]},{"id":"f8293c4f.07d6c","type":"function","name":"","func":"msg.url = \"http://maps.google.com/maps/api/geocode/xml?address=\" + msg.payload + \"&sensor=false\"\nreturn msg;","outputs":1,"x":336,"y":441,"z":"d05d9cdf.2fa26","wires":[["75ee0f21.8a11f"]]},{"id":"876a34f0.7895c8","type":"debug","name":"openstreetmap","active":true,"console":"false","complete":"false","x":686,"y":118,"z":"d05d9cdf.2fa26","wires":[]},{"id":"fa5bd875.05a428","type":"xml2js","name":"","x":564,"y":458,"z":"d05d9cdf.2fa26","wires":[["3f3cb5d9.c0c34a"]]},{"id":"3f3cb5d9.c0c34a","type":"function","name":"","func":"\n\ntry {\nvar lat = msg.payload.GeocodeResponse.result[0].geometry[0].location[0].lat[0];\nvar lng = msg.payload.GeocodeResponse.result[0].geometry[0].location[0].lng[0];\nmsg.payload = {\"lat\":lat,\"lng\":lng};\nreturn msg;\n}\ncatch(e)\n{\nreturn null;\n}\n\n","outputs":1,"x":679,"y":458,"z":"d05d9cdf.2fa26","wires":[["63ac61ec.9c53a"]]},{"id":"c7be567a.3841a8","type":"function","name":"","func":"msg.payload = msg.tweet.user.location;\nreturn msg;","outputs":1,"x":104,"y":337,"z":"d05d9cdf.2fa26","wires":[["6e9ab6d9.916548"]]},{"id":"6e9ab6d9.916548","type":"switch","name":"null check","property":"payload.length","rules":[{"t":"gt","v":"3"},{"t":"else"}],"checkall":"false","outputs":2,"x":215,"y":296,"z":"d05d9cdf.2fa26","wires":[["f8293c4f.07d6c","c164298d.3e9bd8","ae6243d1.519dc"],["c34e6228.3cb1a"]]},{"id":"c34e6228.3cb1a","type":"debug","name":"No","active":true,"console":"false","complete":"false","x":511,"y":332,"z":"d05d9cdf.2fa26","wires":[]},{"id":"c164298d.3e9bd8","type":"debug","name":"Yes","active":true,"console":"false","complete":"false","x":513,"y":231,"z":"d05d9cdf.2fa26","wires":[]},{"id":"5dc1e0dd.a23e2","type":"function","name":"5 second Rate Limiter","func":"var interval = (1000*5); // minimum interval between messages (ms)\ncontext.lastTime = context.lastTime || 0;\n\nvar now = Date.now();\n\nif (now-context.lastTime < interval) {\n  return null;\n} \nelse\n{\n   context.lastTime = now;\n  return msg;\n}\n\n\n\n","outputs":1,"x":135,"y":160,"z":"d05d9cdf.2fa26","wires":[["c7be567a.3841a8"]]},{"id":"ba6a721.f45959","type":"http request","name":"","method":"GET","url":"","x":505,"y":77,"z":"d05d9cdf.2fa26","wires":[["ad6dec7.f52921"]]},{"id":"ae6243d1.519dc","type":"function","name":"","func":"msg.url = \"http://nominatim.openstreetmap.org/search?format=json&q=\"+msg.payload+\"&zoom=18&addressdetails=1\"\nreturn msg;","outputs":1,"x":354,"y":55,"z":"d05d9cdf.2fa26","wires":[["ba6a721.f45959"]]},{"id":"63ac61ec.9c53a","type":"debug","name":"googleapi","active":true,"console":"false","complete":"false","x":732,"y":413,"z":"d05d9cdf.2fa26","wires":[]},{"id":"451fb213.bae04c","type":"twitter in","twitter":"","tags":"hi","user":"false","name":"","topic":"tweets","x":72,"y":87,"z":"d05d9cdf.2fa26","wires":[["5dc1e0dd.a23e2"]]},{"id":"ad6dec7.f52921","type":"function","name":"","func":"\n\ntry {\nvar input = JSON.parse(msg.payload)\nvar lat = input[0].lat;\nvar lng = input[0].lon;\nmsg.payload = {\"lat\":lat,\"lng\":lng};\nreturn msg;\n}\ncatch(e)\n{\nreturn null;\n}\n\n","outputs":1,"x":517,"y":150,"z":"d05d9cdf.2fa26","wires":[["876a34f0.7895c8"]]}]
Hardware-Hacks

Flow Info

created 3 years, 2 months ago

Node Types

Core
  • debug (x4)
  • function (x6)
  • http request (x2)
  • switch (x1)
  • twitter in (x1)
Other
  • xml2js (x1)

Tags

  • geolocation
  • twitter
  • googleapi
  • delay
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option