Local search on dotspott
Dec 12 2010 · Web Technologies
Local search is now available on the dotspott web client; allowing you to search for local venues and add them to your list of spotts.
The Google Maps API v3, which is used by dotspott, doesn’t really allow for local search and the Local Search API itself is deprecated (however, as per Google’s deprecation policy, it should be available until Nov. 2013). What I did was use gmaps-api-v3-googlebar, which allows adding a google-bar like control to the map.
One interesting thing I needed to do that wasn’t directly possible with gmaps-api-v3-googlebar update a few other things after one of the search results were selected. I wanted to avoid touching the gmaps-api-v3-googlebar code, so I did this by getting a reference to the existing event handler, then overwriting it with a new function, which called the previous event handler function.
Here’s an example where we grab the reference to the existing selectResult event handler (searchResultPre), overwrite with a new event handler, call the previous handler (binding to window.gbar, the instance of window.jeremy.jGoogleBar; binding is necessary b/c the event handler references this internally), then add some new functionality where we modify a paragraph element in the DOM (id = map_position) to show the position of the local marker that is selected.
selectResultPre = window.jeremy.jGoogleBar.prototype['selectResult'];
window.jeremy.jGoogleBar.prototype['selectResult'] = function (result)
var searcher = window.jeremy.gLocalSearch.searchers;
var results = searcher['results'];
var lmarker = result['marker'];
oh, and yes, this is using jQuery; $(‘#map_position’) should have given it away.