Google Maps in Max

Draw points in Max by sending latitude and longitude to a Web client via Osc and web sockets.

Uses Ruby, WebSockets, Chrome, Google Maps API, Osc, Max, Jquery, and Node.js… But the Max patch is actually quite simple.

Based on this geocoding tutorial:


folder: google-maps


main Max patch
  • googlemaptest.maxpat
html and javascript for Google API
  • js/ (folder containing javascript code for map client)
  • markers.html (web client)
  • mapserver.rb (Osc and Websockets server)
node.js (optional)
  • nodeserver.js (local node.js webserver)

running node.js local web server (optional)

To run the project locally, you will either need to install node.js or have a local web server. The instructions assume that you have installed node, as well as the http package.

If you don’t want to bother with node, there is also an online version of the web client running at

intalling ruby gems

Running Ruby 2.0 as well as the following gems:

  • osc-ruby
  • em-websocket
  • json


1. If you are using the online Web client, go to this URL in a Google Chrome browser: then skip to step 4.

2. In a terminal window start the node webserver

node nodeserver

3. Launch a Google Chrome web browser and type in this URL

4. In another terminal window start the ruby server for Osc and websockets

ruby mapserver.rb

5. Now in the Web Client (Chrome) press the “OSC” button underneath the map – to open the web sockets connection with the ruby server.

6. Open the Max patch:


7. Now you should be able to click on the message boxes for Bethel and Rumford in the Max patch to add location markers to the map in the browser.


Updating ruby in Mac OS

5/2014 These instructions failed on Snow leopard 10.6.8 – see following note:

Note: To install rvm, there are some dependencies – for example gcc – If you have not installed xcode developer tools, or any typical linux tools – rvm will try to install homebew and probably fail. So it may not be practical to update your version of Ruby this way…

original post

Used rvm – explained here – but I have extracted relevant instructions below:

start here:

1. Update /etc/paths as explained here:

sudo nano /etc/paths

Add 2 following lines:



then reboot your terminal

2. Then install rvm:

As The Tin Man suggests (above) RVM (Ruby Version Manager) is the Standard for upgrading your Ruby installation on OSX:

To get started, open a Terminal Window and issue the following command:

\curl -L | bash -s stable --ruby

( you will need to trust the RVM Dev Team that the command is not malicious – if you’re a paranoid penguin like me, you can always go read the source )

3. When it’s complete you need to restart the terminal

4. To get the rvm command working.

rvm list known

( shows you the latest available versions of Ruby )

rvm install ruby-2.0.0-p247

For a specific version, followed by

rvm use ruby-2.0.0-p247

or if you just want the latest (current) version:

rvm install current
rvm use current

( installs the current stable release – at time of writing ruby-2.0.0-p247 – please update this wiki when new versions released )

Ruby tweetstream gem

Access to the Twitter streaming API


This gem looks to be a possible solution for connecting Max to Google Maps. I’m guessing that the code will look very similar to the ruby code which uses the twitter gem for status updates.

Here’s a blog entry:

Client documentation:

Here’s the Twitter documentation on whats getting returned:


Max Twitter client using ruby

Send and receive Tweets using Max via OSC to a background ruby server.

An advantage of this method is that both the patch and the server are  compact and easy to understand. The Max patch does things in a Max way. And likewise with the ruby scripts.


folder: twitter-ruby


  • twitter-client.maxpat
  • twitter-server-send.rb (for sending Tweets)
  • twitter-server-get.rb (for receiving Tweets)
ruby gems

The ruby script requires installation of the following gems

  • json
  • osc-ruby
  • twitter

For example:

# sudo gem install twitter

Twitter authorization

In addition to having a Twitter account, you will need to set up a Twitter application from the developer site here:

Good instructions on how to do this can be found in this post under this heading: So you want to use the Twitter v1.1 API?

When you get to step 5 – in the instructions – instead of writing your own code, just use a text editor to copy your access tokens into these ruby programs:

  • twitter-server-send.rb
  • twitter-server-get.rb

Replace the strings in this line of code by copying and pasting the appropriate ones from your Twitter application:

twitterClient = do |config|
  config.consumer_key = "mqQtoYh16343tDFG3BK7QQ"       
  config.consumer_secret = "X0KexjlK49fhhrnn9EztapZfATCQqWCc5fXVJH2pE"      
  config.oauth_token = "205589709-5krgh9FR3KkLGRDnewiU7GKKBMA6i2La84c"       
  config.oauth_token_secret = "LNARAeooN2vkklkF006GRdihQ5D8YYkm8dYvEs68M"  
Yeah – its cryptic, but trivial compared to writing the ouath code. Just a reminder, if even one letter or quote mark, or anything is out of place, the authorization will fail.


(note: currently running with ruby version 2.0) Display your ruby version by typing: ruby –version

Sending Tweets
  • Open the Max patch: twitter-client.maxpat
  • In a terminal window run the ruby script:
# ./twitter-server-send.rb

  • In the Max patch, type in a Tweet. Press the green button to send. 
  • When you have tweeted enough, end the ruby server program by typing <ctrl-c>
 Receiving Tweets
  • Open the Max patch: twitter-client.maxpat
  • In a terminal window run the ruby script:
  • From Twitter, send a Tweet to the user name embedded in the server
# ./twitter-server-get.rb

Both ruby servers can run at the same time.

What’s next?

  • Parse incoming Tweets into various components
  • Combine the 2 Ruby servers

revision history

  • 5/21/2014 – refactored app names. Added receive server
  • 5/19/2004 – moved to twitter-ruby folder
  • 1/18/2014 – minor fixes to ruby server for current ruby version 2.0
  • 9/7/2013 – uses oauth to communicate directly to Twitter from ruby

Send Tweets with a Little Tikes piano

This project uses the Max fzero~ object to detect which key of the piano gets pressed and send a pre-written Tweet like “Signs point to yellow” based on the color of the key.

It works with the Internet sensors project that sends Tweets from Max using Ruby.


folder: twitter-ruby


  1. Follow instructions here to send Tweets using Max and Ruby:
  2. At this point you will have a Max patch open and a Ruby server running in a terminal window.
  3. Now open little-tikes.maxpat
  4. Carefully play individual tones on the Little Tikes piano. 


fzero~ is probably not the best choice for this. It doesn’t work above 2500hz which means it won’t probably distinguish between the lowest and highest key which are an octave apart. In fact the Little-Tikes piano, for a pitched instrument, is difficult to analyze. Due to relatively equal weight of partials to fundamental, and the quick decay. Other choices, would be pitch~ (Jehan) fiddle~ (Pucket…)

I remember seeing an Arduino project where somebody did this in reverse – actually built a motorized striker to play the piano)

… insert link to video here…


hardware control of webaudio API


This is a tweak of a demo program by Boris Smus from

The audio is generated in the web browser using the webaudio API. Oscillator frequency is being controlled by an iPod touch running touchOSC.

A ruby program is running in the background. It starts 2 servers, one to handle Osc messages from the iPod. and a websockets server which passes Osc messages to the web client in the browser, which parses the data and sets oscillator frequency.

local source files in tkzic/web-audio-api/webaudioapi/content/posts/oscillator-ws


(these are for my local files – source has not been published yet) Please contact me directly for more information about this code. Or have a look at a very similar example at:

1. run the node webserver in tkzic/

node nodeserver.js

(it will run on localhost port 8081 – for example

2. In Chrome web browser, run:

The following screen will appear:

3. From a terminal prompt run this ruby script (in tkzic/web-audio-api/webaudioapi/content/posts/oscillator-ws)


4. In webpage in Chrome, click the sockets button – the ruby server should open a socket connection, also click the play/pause button to start the oscillator

5. In touchOSC point the host to the ip address of the laptop (ie., running on default ports, (out 8000, in 9000)

6. In touchOSC run the ‘simple’ layout and move fader1 to change the pitch of the oscillator

Note: You will probably also want to open the developer javascript console in Chrome to see what is going on.

next step

Need to clean up the ruby server code to handle error conditions, ie., network interruptions, missing files, browser incompatibility, etc.,