Where’s the Center?

In Figure 4, local search found a company called Peanut Butter Publishing in San Francisco, California. Why SF? Because that’s the default local center place. That was probably chosen because few have heard of Mountain View, CA where the Googleplex (i.e., Google headquarters) is.

You can change the location by calling a method that belongs to GlocalSearch called setCenterPoint. Figure 5 shows what happens when we use that method to change the center point to Jackson Hole, Wyoming.

The local search now points to the Bunnery, a little breakfast shop in Jackson that does its own baking. (Click on the link and you’ll find some good reasons to go there.) Example 4, which follows Figure 5, shows the code change you have to make to change the center point.

sample.html with the local search center point set to Jackson Hole

Figure 5. sample.html with the local search center point set to Jackson Hole

Example 4. doSearch with call to setCenterPoint

<script language="Javascript" type="text/javascript">

function doSearch() {

  // Instantiate control, web search service
  var search = new GSearchControl();
  var local = new GlocalSearch();

  // Change local search center point
  local.setCenterPoint( “Jackson Hole, Wyoming” );

  // Add a web search
  search.addSearcher( new GwebSearch() );
  search.addSearcher( local ); search.addSearcher( new GimageSearch() ); search.addSearcher( new GblogSearch() ); search.addSearcher( new GvideoSearch() ); search.addSearcher( ...

Get Google Ajax Search API now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.