Google 地图 Api 融合 Table select 名称等于变量的几何体
Google Maps Api Fusion Table select geometry where name equals variable
基本上我想将 inputValue 变量传递到融合 table 查询中,以查找列 'Name' 的值等于 inputValue 的几何图形。
我只想知道这应该怎么写。任何帮助将不胜感激。代码如下:
jQuery(document).ready(function($) {
// function init() {
var baseLatLng = new google.maps.LatLng(52.7713,-1.5550);
var newLatLng;
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 12,
center: baseLatLng
});
var searchOptions = {
center: baseLatLng,
mapTypeID: 'roadmap',
componentRestrictions: {country: "uk"}
};
var input = document.getElementById('search');
var autocomplete = new google.maps.places.Autocomplete(input, searchOptions);
var inputValue = document.getElementById('search').value;
var geocoder = new google.maps.Geocoder();
$("#go").click(function(event) {
event.preventDefault();
geocodeAddress(geocoder);
layer.setMap(map);
});
function geocodeAddress(geocoder) {
var address = document.getElementById('search').value;
geocoder.geocode({address: address, region: 'uk'}, function(results, status) {
if (status === 'OK') {
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
var latitude = results[0].geometry.location.lat();
var longitude = results[0].geometry.location.lng()
newLatLng = latitude + ',' + longitude;
document.getElementById('results').innerHTML = "latitude:" + latitude + "<br>" + "longitude:" + longitude;
});
}
var layer = new google.maps.FusionTablesLayer({
query: {
select: 'Geometry',
from: 'xxxx',
where: "'Name' = inputValue" ---HERE!
},
styles: [{
polygonOptions: {
fillColor: '#00FF00',
fillOpacity: 0.3
}
}]
});
});
谢谢,
奥利
找出解决方案。以后我会把这个留给任何人。
function getBoundry() {
var address = document.getElementById('search').value;
var query = "\"\'Name\' = " + "\'" + address + "\'" + '\"';
var layer = new google.maps.FusionTablesLayer({
query: {
select: 'Geometry',
from: 'xxxxx',
where: query
},
styles: [{
polygonOptions: {
fillColor: '#00FF00',
fillOpacity: 0.3
}
}]
});
layer.setMap(map);
}
然后在点击事件中调用该函数
$("#go").click(function(event) {
event.preventDefault();
getBoundry();
});
基本上我想将 inputValue 变量传递到融合 table 查询中,以查找列 'Name' 的值等于 inputValue 的几何图形。
我只想知道这应该怎么写。任何帮助将不胜感激。代码如下:
jQuery(document).ready(function($) {
// function init() {
var baseLatLng = new google.maps.LatLng(52.7713,-1.5550);
var newLatLng;
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 12,
center: baseLatLng
});
var searchOptions = {
center: baseLatLng,
mapTypeID: 'roadmap',
componentRestrictions: {country: "uk"}
};
var input = document.getElementById('search');
var autocomplete = new google.maps.places.Autocomplete(input, searchOptions);
var inputValue = document.getElementById('search').value;
var geocoder = new google.maps.Geocoder();
$("#go").click(function(event) {
event.preventDefault();
geocodeAddress(geocoder);
layer.setMap(map);
});
function geocodeAddress(geocoder) {
var address = document.getElementById('search').value;
geocoder.geocode({address: address, region: 'uk'}, function(results, status) {
if (status === 'OK') {
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
var latitude = results[0].geometry.location.lat();
var longitude = results[0].geometry.location.lng()
newLatLng = latitude + ',' + longitude;
document.getElementById('results').innerHTML = "latitude:" + latitude + "<br>" + "longitude:" + longitude;
});
}
var layer = new google.maps.FusionTablesLayer({
query: {
select: 'Geometry',
from: 'xxxx',
where: "'Name' = inputValue" ---HERE!
},
styles: [{
polygonOptions: {
fillColor: '#00FF00',
fillOpacity: 0.3
}
}]
});
});
谢谢, 奥利
找出解决方案。以后我会把这个留给任何人。
function getBoundry() {
var address = document.getElementById('search').value;
var query = "\"\'Name\' = " + "\'" + address + "\'" + '\"';
var layer = new google.maps.FusionTablesLayer({
query: {
select: 'Geometry',
from: 'xxxxx',
where: query
},
styles: [{
polygonOptions: {
fillColor: '#00FF00',
fillOpacity: 0.3
}
}]
});
layer.setMap(map);
}
然后在点击事件中调用该函数
$("#go").click(function(event) {
event.preventDefault();
getBoundry();
});