It is definitely possible to do what you want to do, but it's not that easy. In the example the location to pan to is calculated by the Google Geocoding API using an address. But you don't really have the address (i.e. content of locationColumn
) in your JavaScript code. It depends what kind of information you store in the locationColumn
, I suppose it's some kind of address that can be geocoded.
Therefore you have to send a select statement directly to Fusion Tables. Google Fusion Tables has a JSONP interface that you can use for this purpose.
var gftUrl = 'http://www.google.com/fusiontables/api/query?';
var jsonUrlTail = '&jsonCallback=?';
var query = 'select ' + locationColumn + ' from ' + tableid + ' where ' + where;
var params = "sql=" + encodeURI(query + jsonUrlTail);
var myCallback = function(data,status) {
if(status !== 'success') {
window.alert('Call to Google Fusion Tables failed: ' + status);
return;
}
var address = data.table.rows[0][0];
/* start code from google example */
geocoder.geocode({
address: address
}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
map.setZoom(10);
// OPTIONAL: run spatial query to find results within bounds.
var sw = map.getBounds().getSouthWest();
var ne = map.getBounds().getNorthEast();
var where = 'ST_INTERSECTS(' + locationColumn +
', RECTANGLE(LATLNG' + sw + ', LATLNG' + ne + '))';
layer.setOptions({
query: {
select: locationColumn,
from: tableId,
where: where
}
});
} else {
window.alert('Address could not be geocoded: ' + status);
}
});
/* end code from google example */
}
var jqxhr = $.post(gftUrl, params, myCallback, "jsonp"); /* jsonp parameter is very important */
In this example I use jQuery for the $.post
function.