Google Maps API Tutorial© 2008, 2009 Mike Williams |
Translate this page: |
GoogleBar OptionsThe GoogleBar allows you to achieve similar functionality to what you would get by using the Google AJAX Search API to perform a Local Search, but provides a few advantages:
OptionsThe possible entries in the googleBarOptions are:
The first six options are fairly straight forward, but the callback functions need a bit of explanation: onIdleCallbackThis function is called when the GoogleBar is opened for the first time, and called again whenever the previous results are cleared. It is not called if a second search is executed without the user explicitly clearing the previous results.No parameters are passed. onSearchCompleteCallbackThis function is called when the search is complete, before the results are plotted.There is one parameter, a reference to a GlocalSearch object, see Official Class reference Of particular interest is the .results[] array, which is an array of GlocalResult() objects, see Official Class reference You can read that information, but also, because it's a reference, you can modify the contents of the .result[] array. The .html will have already been calculated, so changing things like the .results[i].city won't affect what gets displayed in the info window. If you want to change the info window contents at this point, then you need to change the .results[i].html.innerHTML. onMarkersSetCallbackThis function is called when the API has created markers corresponding to the search results.
There is one parameter, an array of anonymous Objects. onGenerateMarkerHtmlCallbackThis function is called whenever an info window is about to be opened.The parameters are:
Simple result filtering exampleThis example uses onSearchCompleteCallback to filter the search results, reducing the number of results to no more than two.Simple info window modificationThis example uses onGenerateMarkerHtmlCallback to read information from the GMarker and from the GlocalResult to modify the contents of the info window at the time that the info window is opened.Advanced example: add ELabelsThis advanced example uses all the GoogleBar Options. It displays an Elabel alongside each marker, and in order to do that it uses the callback functions like this:onIdleCallback uses map.clearOverlays() to remove the old ELabels onSearchCompleteCallback uses map.clearOverlays() to remove the old ELabels onMarkersSetCallback reads the location of each GMarker and the titleNoFormatting of each GlocalResult and uses that information to create an ELabel. onGenerateMarkerHtmlCallback hides the ELabel corresponding to the marker on which the info window is opening. |