English 中文(简体)
Problem with Javascript Menus on Google Map API using fusiontables
原标题:

Right now I am currently creating a map that will have a javascript menu allowing users to change to different map views using the Google fusion table overlays. I would really appreciate it if you could help me out with a problem that is preventing me from completing the project.

This is my Google Maps HTML Page:

<html> 
<head> 
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> 
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
<!DOCTYPE html>
<title>Met Sacramento Internship Map</title> 

<!-- Style --> 
<style> 
  body { font-family: Arial, sans-serif; }
  #map_canvas { height: 500px; width:600px; }
</style> 

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 
<script type="text/javascript"> 
    var tableid = 567682;
    var layer = new google.maps.FusionTablesLayer(567682); 

  function initialize() {
    var latlng = new google.maps.LatLng(37.5213829, -122.172534);
    var myOptions = {
      zoom: 8,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);
          layer.setMap(map);
  }
  //Change the query based on the user s selection
function changeMap(delivery) {
  layer.setQuery("SELECT Address FROM " + tableid + " WHERE delivery LIKE  " + delivery + " ");
}
</script>

 </script> 

</head> 
<body onload="initialize();">  
  Internship Status <select onchange="changeMap(this.value);"> 
    <option value="%">--Select--</option>
  <option value="ANIMALS">Animals</option>
  <option value="BUSINESS">Business</option>
  </select> <div id="map_canvas"></div>
</body> 
</html>

My problem occurs when I add this code:

  //Change the query based on the user s selection
function changeMap(animals) {
  layer.setQuery("SELECT Address FROM " + tableid + " WHERE Animals LIKE  " + Animals + " ");

Any help would be greatly appreciated, I am fairly new to fusion tables, the Google Maps API, and Javascript.

问题回答

Looking at table 567682, I don t see a column named "Animals". Make sure that your table contains a column named "Animals" with values "ANIMALS" and "BUSINESS" in it, since your WHERE clause is filtering on that column.

The variable Animals is not spelled correctly. In the function header you write it with lower A "animals" whereas in the query you refer with upper case "Animals"...

Looks like that Fusion table isn t playing nice with your LIKE SQL operator, even though google says it s supported

I got it working by changing the query to use CONTAINS and option values like this:

layer.setQuery("SELECT Address,  Interest Area  FROM " + tableid + " WHERE  Interest Area  CONTAINS  " + delivery + " "); 

<option value="Animals">Animals</option>
<option value="Business">Business</option>




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签