Friday, June 3, 2011

Build local search on phone using Google places and KooKoo

Mashups are all the rage nowadays. With an increasing number of API’s out there, the possibilities are countless. Here’s one display of an interesting mashup using Google Places and the KooKoo API. 

Note: The demo can be accessed at 91-40-39411020. Pin: 1748 91-40-30512867 (The example application may not work on QWERTY keyboard phones like blackberry)
Step 1: The ‘Idea’
The basic idea here is to build an Interactive Voice Response System (IVRS) that is accessible through the phone. Something like JustDial, but without the hassle of talking to another human on the other end. You tell the phone the area you’re interested in, what type of establishments you’re looking for (hotels, restaurants or in an emergency, hospitals) and you will get a list of establishments that match the criteria you specified. Simple and fast.
Step 2: Identify functionality needed to develop the idea
The functionalities identified for this application are:
  1. Telephony interface for the IVRS
  2. Database to store a list of places
  3. Geocode (convert to latitude, longitude) the place given as input
  4. Find establishments of given type around the desired place
Step 3: Identify the API’s
The API’s required are
Google Geocoding API
This will account for functionality 3
Google Places API
This will account for functionality 4

KooKoo API
Provides the telephony interface, i.e., functionality 1

Sign up with Google API at to get an API key using which you can access the Google API functions.
Sign up with KooKoo to get a phone number for your application.

Step 4: Integrate the API’s
The first step is to register for a developer account at KooKoo. Let’s create a PHP page called “ivrs.php” and update the application URL to point to it.
Let’s now look at the code design that’s going to go into ivrs.php.
1. Include the KooKoo library to access the KooKoo functions.
2. When a new call comes, ask the caller to enter the location details like,“Enter the first 3 letters of the place followed by hash. For example, 2 6 3 hash for Ameerpet.”

We handle the new call event by instructing the user to input the first 3 letters of the desired place followed by a hash. Here we have mapped each place to a 3 digit code using the first 3 letters of the place and their corresponding number on a phone keypad.

The digit code to place mapping is maintained in a simple hashmap as shown below:

$hashmap["226"]="Banjara Hills";
More places can be added as and when required.

3. Ask the user to select an establishment like "Press 1 for ATM, press 2 for hospitals" etc

4. Using Google Geocoding API we geocode the place, i.e., we convert it into latitude,longitude. This is needed because the Google places API needs the Lat Long parameters and does not take a place parameter.

5. Using Google Places API we look for establishments of the type specified by the user around the location specified.

6. Parse the JSON result and play them back to the user or send an SMS.

Thats it. So with just around 50 lines of code, we have a competitor to JustDial :), thanks to Mashups.
The code can be downloaded here.
The code can be customized to your heart’s content. Add more places (the current database contains 20 places within Hyderabad) and add more “types” of establishments (dentists, doctors, etc.) The full list of types is here.
1. The code has to be updated to handle conflicts,two places could have the same first 3 letters. 
2. Update the DTMF interface to voice.

Note: This is a guest blog by our Intern, Vinay Kola. This has been adapted from his blog, Infinite Improbability
Vinay is "Student at IIT Kharagpur. Man Utd fanatic. Technophile. Music lover" as per his twitter account @vinaykola. 
He is doing a great job at Ozonetel and we hope he goes on to start a business on top of our KooKoo platform.