3

How can I zoom a Google Maps control to fit the contents of a Fusion Table layer? The layer only contains pushpin / marker point data.

One method is to perform a REST query on the Fusion Table and to calculate the bounds, and zoom to these (i.e. as illustrated here: http://gmaps-samples.googlecode.com/svn/trunk/fusiontables/fitbounds.html ). However this seems very inefficient - especially for larger datasets, because all of the table data has to be sent to the client and compared.

This question appears to ask the same query, but the answer does not apply. The answer simply queries the data for the current map extents. Nice and efficient, but the opposite of what I want. I want to zoom to display all available data.

1 Answer 1

2

You can get your all your table data and find the bounds from the response:

      var bounds = new google.maps.LatLngBounds();
  for(i = 0; i < numRows; i++) {
      var point = new google.maps.LatLng(
          parseFloat(response.getDataTable().getValue(i, 0)),
          parseFloat(response.getDataTable().getValue(i, 1)));
      bounds.extend(point);
  }
  // zoom to the bounds
  map.fitBounds(bounds);
}

This comes from a good example:

http://www.geocodezip.com/www_vciregionmap_comC.html and view source

2
  • Thanks for the quick reply. Although perhaps more elegant in the implementation, this is essentially the same approach as the Google sample. It queries all of the points and then calculates the bounds locally on the client. My customer has a lot of pushpin data (yes, I know...) so I would prefer a more efficient solution (eg. getting the bounds directly from Fusion) if possible.
    – winwaed
    Mar 15, 2012 at 14:04
  • In the end, I had to use a variation of this. I used an AJAX call to my server to get the data and use it to set the bounds.
    – winwaed
    Sep 23, 2014 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.