Search in Fusion Tables and Zoom to results

ⅰ亾dé卋堺 提交于 2019-11-30 06:06:22

问题


Hi all here's my situation: http://www.tamrielma.ps/skyrim/

I've added a search based on this well know example: https://developers.google.com/fusiontables/docs/samples/autocomplete But it's not enough :D and I want that the map zooms and centers on the basis of the search results (that's a single markers not a group of, so I imagine that's not a "bound related" solution).

Thanks in advance for any suggestion


回答1:


Interesting map. :-) I see you are already using the Google.visualization library for your autocompplete set up. I think that the same library (which uses FT JSONP API I believe) could be used to get the location values via a a callback, similar to your getData() callback. E.g.

function changeQuery(value) {
 value = value.replace("'", "\\'");
 layerMarkers.setQuery("SELECT Location FROM "+ fusione +" WHERE Name = '" + value + "'");

 // ADDED, using same query as above
  var queryText = encodeURIComponent( "SELECT Location FROM "+ fusione +" WHERE Name = '" + value + "'");
  var query = new google.visualization.Query('http://www.google.com/fusiontables/gvizdata?tq='  + queryText);
  query.send(getLocationData);

}
// location may need parsing into LatLng object
function getLocationData(response) {
    numRows = response.getDataTable().getNumberOfRows();
    if(numRows == 1){
          var loc_str = response.getDataTable().getValue(0, 0));
          var tmp = loc_str.split(" ");
          var lat = parseFloat(tmp[0]);
          var lng = parseFloat(tmp[1]);
          var zoom_level = 10;
          var location = new google.maps.LatLng(lat,lng);
          map.setCenter(location);
          map.setZoom(zoom_level);
    }

}


来源:https://stackoverflow.com/questions/10206033/search-in-fusion-tables-and-zoom-to-results

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!