How to add Google Search to your Maps API application

Monday, August 14, 2006 at 11:41:00 PM

The Google AJAX Search API is designed to work seamlessly with the Google Maps API. One way it adds instant value is to allow your maps-based applications to execute a search and then plot those search results on the map. Our model for this is simple and straightforward. Each search result is a JavaScript object that contains a number of properties including a URL, title, array of phone numbers, street address, city, etc. In addition, each search result contains the latitude and longitude of the result.

Adding a search result onto a map is as simple as:

var latLng = GLatLng(parseFloat(result.lat), parseFloat(result.lng));
var marker = new GMarker(latLng);
myMap.addOverlay(marker);

The AJAX Search API team has produced a number of sample applications to teach the basics of search integrated maps mashups. Two of the most popular are My Favorite Places and My Phone List. Take a look and see if they inspire you to add search to your maps based mashups.

As an example of this search enhanced Maps mashup idea, we have built a Google Gadget using these two APIs. Give the new The Google Map Search gadget a shot.