English 中文(简体)
Using a variable for LatLng position in SQL expr for Google Fusion Tables
原标题:

I m trying to display points from a Google Fusion Table that renders them based on a geocoded event. The event centers the map, displays a marker, but I d like it to make a new selection on the table based on the new map center and a fixed radius. My attempt is to pass a variable to the spatial query but I m not sure where to put it or if I m calling it right.

For that matter, it would be cool to even just use an onClick event to trigger the new query but it s the same problemo.

Thanks in advance...Rafa

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

<title>Selected Records from Google Fusion Table based on Geocoded Location</title> 

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

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 
<script type="text/javascript"> 

var layer;
var geocoder;
var map;
var tableid = 411675;

// initialize the map =====================
function initialize() {

    geocoder = new google.maps.Geocoder();  
  var latlng = new google.maps.LatLng(45.526, -122.6684);
    var myOptions = {
          zoom: 8,
          center: latlng,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        }
    map = new google.maps.Map(document.getElementById( map_canvas ), myOptions);
  layer = new google.maps.FusionTablesLayer(tableid);
  layer.setMap(map);    
}

// operates geocoder =====================
function codeAddress() {
    var gcAddress = document.getElementById("gcAddress").value;
    geocoder.geocode( {  address : gcAddress}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        map.setCenter(results[0].geometry.location);
        var marker = new google.maps.Marker({
            map: map, 
            position: results[0].geometry.location
        });
                layer.setQuery("SELECT Address FROM " + tableid + " WHERE ST_INTERSECTS(Address, CIRCLE(LATLNG(" + position + "), 5000))");
      } else {
        alert("Geocode was not successful for the following reason: " + status);
      }
    });
}
</script> 
</head> 

<body onload="initialize();"> 
  <div> 
        <input id="gcAddress" type="textbox" value="Hillsboro, OR"> 
        <input type="button" value="Geocode" onclick="codeAddress()">
    </div>
    <div id="map_canvas"></div>
</body>
最佳回答

I think you might have had your expression slightly wrong.

var query = "SELECT Address FROM " + tableid + " WHERE ST_INTERSECTS(Address, CIRCLE(LATLNG" + marker.position + ", 20000))";

I updated the position to read marker.position, removed the brackets as it comes with it s own. I then expanded the radius to 20000 for testing purposes.

This worked for me. If you need to test queries you can use an example such as

http://kh-samples.googlecode.com/svn/trunk/talks/samples/fusiontableslayer.html

As a basis for testing (just save and modify it for your table), hopefully will help a bundle :)

Hope this helps.

Matt

问题回答

暂无回答




相关问题
How to decide the current point reach on google map?

How to decide the current point reach on google map? I have a list of points (pickup points) of a route that I want to show in my google map with polyline. Now i have to get the current location of ...

Topographical or relief data in Map APIs

I was wondering if anyone knew of any map APIs that offer topographical or relief data? I ve had a quick look at Google and Bing APIs, but could find nothing there. Google allow you to view a map as ...

Using maps on Windows Mobile

I m experimenting with maps on different mobile platforms. Getting Google Maps to work on Android was easy, following this tutorial. Getting the same to work on Windows Mobile is a different matter. ...

Adding a custom icon to a google map

I need a hand adding a custom icon to some Google Maps javascript. Code below for your reference: function populateMap() { var map = new GMap2(document.getElementById("map")); map.setCenter(new ...

RSS to KML Overlay

I m want to display my blog as a Google Map overlay (each post contains geotags). How can I dynamically create a KML overlay from an RSS? Or better, how can I create a loop (PHP) that would display ...

开放街道地图管理员

我需要开放Street的标记管理员。 地图,如山角地图。

热门标签