Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm trying to apply the same code as this exmaple to zoom the google map to a KML Markers loaded into Fusion Table Layer.

The example code works for KML Polygon loaded into Fusion Table Layer but not for markers. Does anyone know how to apply that to KML markers?

kml example:

<Point><coordinates>-59.028645,50.772916,0.0</coordinates></Point>

script:

query = "SELECT * FROM  1eiOWq49sR8DXdymYALNdItE0uf-f4mNRbyJOVOU";
query.send(zoom2query);

function zoom2query(query) {
   // zoom and center map on query results
   //set the query using the parameter
   var queryText = encodeURIComponent(query);
   var query = new google.visualization.Query('http://www.google.com/fusiontables/gvizdata?tq='  + queryText);


    //set the callback function
    query.send(zoomTo);

      }

  function zoomTo(response) {
    if (!response) {
      alert('no response');
      return;
    }
    if (response.isError()) {
      alert('Error in query: ' + response.getMessage() + ' ' ++ response.getDetailedMessage());
      return;
    } 

      FTresponse = response;
      //for more information on the response object, see the documentation
      //http://code.google.com/apis/visualization/documentation/reference.html#QueryResponse
      numRows = response.getDataTable().getNumberOfRows();
      numCols = response.getDataTable().getNumberOfColumns();
      var geoXml = new geoXML3.parser();
      var bounds = new google.maps.LatLngBounds();
      for (var i = 0; i < numCols; i++){
        if (FTresponse.getDataTable().getColumnLabel(i) == 'geometry') {
         var ColIndex = i;
        }
      }
      if (!ColIndex){
        alert('Geometry column "geometry" not found.')
      }
      for (var i = 0; i < numRows; i++){
        var bounds = new google.maps.LatLngBounds();
        for(i = 0; i < numRows; i++) {
            var kml = FTresponse.getDataTable().getValue(i,ColIndex);
            geoXml.parseKmlString("<Placemark>"+kml+"</Placemark>");
            bounds.union(geoXml.docs[i].bounds);
        }
        // zoom to the bounds
        map.fitBounds(bounds);
      }
share|improve this question
    
This post was edited and now the code above is correct. You can use it to zoom on kml markers loaded in fusion table layer. –  DemarsM Mar 8 '13 at 14:58
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.