Location autocomplete for Google Calendar™

Posted by

In the process of building our startup (we provide simple account management and sharing for teams), I’ve had to attend lots of meetings. We met people for fundraising,  prospective candidates (we’re hiring engineers and business people—email us at at jobs@lectorius.com if you’re interested), and customers all over the place.  Throughout the process Google Calendar (and Google Now) has been invaluable in keeping me organized.

The one glaring flaw with Calendar is the fact that adding locations to events is not easy. I usually have to look up a location on Google Maps, Foursquare, or Yelp and then copy and paste the location into the Where box. I decided to solve this by writing a chrome extension to automatically fill in this form.  It’s been super useful to us and some friends who’ve been trying out, so we decided to make this the first contribution to our Mitro.co’s labs page!

Get the free Chrome extension

mitro-calendar-google-plugin

Caveat: Editing old events doesn’t work quite right

First off, (for complicated reasons we’ll get into later), the Extension doesn’t work properly if you try to edit old events. If you edit an old event, you will need to change another field in addition to editing the location (or do something like add a space to the location that gets filled in) otherwise your modification won’t be saved to Google Calendar.  I’ll try to make this better in future releases.

Details

This extension is powered by Foursquare’s cool Venue Search API.  I wrote a server that (currently) runs on Google App Engine to proxy and cache these requests to reduce the number of queries that are sent to Foursquare.

The Chrome extension operates by finding the location of the Where box, and using JQueryUI’s autocomplete tool to handle the autocompletions.  Doing this is actually substantially more difficult than it should be: it appears as if Google’s Closure library is caching the content of the forms, and only reads the data from an input element if the user has somehow interacted with it. So, simply changing the contents of the text box (as the autocomplete plugin does) is insufficient; subsequent requests to Google treat the field as if it had never changed. I tried sending various combinations of keyup, keydown, keypress, and textinput events to the textbox, but for some reason, it doesn’t trigger Google Calendar to refresh its data from the textbox.

I recruited the help of Julie Parent, a friend of mine who works on Chrome, and despite working on it for a while, we haven’t been able to figure out why those efforts failed. Our (her) best guess is that this might be related to this WebKit bug, but that remains to be seen.

At any rate, I was able to work around this by overriding XMLHttpRequest(XHR) and rewriting the post data to match the autocompleted location. The one problem (mentioned earlier) is that when editing an event, if the only modification is a new location created by this extension (and not human input) Google doesn’t think anything at all has changed, and doesn’t issue an XHR at all, rendering our hack useless. To get around this, changing anything (e.g. adding a space in the where box) or adding something in the memo, will allow everything to work.

The location autocomplete code is available on github. Check it out! We’d really appreciate any comments/suggestions/patches you might be willing to send our way.

And of course, if working with us sounds like fun, don’t hesitate to reach out: jobs@lectorius.com!

Vijay Pandurangan