Google maps api 3 ZoomToadress在Google Fusion地图上不起作用
我遵循了下面的搜索和缩放示例: 我设法让“重置”按钮工作,但“搜索”按钮不工作。我想知道这是否是因为我使用了2层,但如果是这种情况,我不知道如何使用java脚本进行更正。谢谢你的帮助。谢谢Google maps api 3 ZoomToadress在Google Fusion地图上不起作用,google-maps-api-3,google-fusion-tables,Google Maps Api 3,Google Fusion Tables,我遵循了下面的搜索和缩放示例: 我设法让“重置”按钮工作,但“搜索”按钮不工作。我想知道这是否是因为我使用了2层,但如果是这种情况,我不知道如何使用java脚本进行更正。谢谢你的帮助。谢谢 <html> <head> <meta charset="UTF-8"> <title>Smithfield Foods UK</title> <link rel="stylesheet" type="text/cs
<html>
<head>
<meta charset="UTF-8">
<title>Smithfield Foods UK</title>
<link rel="stylesheet" type="text/css" media="all" href="FusionMapTemplate.css" />
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function initialize() {
var defaultZoom = 10;
var defaultCenter = new google.maps.LatLng(52.6500, 1.2800)
var locationColumn = 'geometry'
var map = new google.maps.Map(document.getElementById('map-canvas'), {
center: defaultCenter,
zoom: defaultZoom,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infoWindow = new google.maps.InfoWindow();
// Initialize the first layer
var FirstLayer = new google.maps.FusionTablesLayer({
query: {
select: 'geometry',
from: '1hpGzmMBg8bDgPOGrAXvc0_QVLSBqQ0O5vpLbfUE'
},
map: map,
styleId: 3,
templateId: 5,
suppressInfoWindows: true
});
google.maps.event.addListener(FirstLayer, 'click', function(e) {windowControl(e, infoWindow, map);
});
// Initialize the second layer
var SecondLayer = new google.maps.FusionTablesLayer({
query: {
select: 'PostCode',
from: '1RrCcRC-1vU0bfHQJTQWqToR-vllSsz9iKnI5WEk'
},
map: map,
styleId: 2,
templateId: 2,
suppressInfoWindows: true
});
google.maps.event.addListener(SecondLayer, 'click', function(e) {windowControl(e, infoWindow, map);
});
var legend = document.createElement('div');
legend.id = 'legend';
var content = [];
content.push('<h3>Density of Polish speaking population</h3>');
content.push('<p><div class="color red1"></div>=>2%<4%');
content.push('<p><div class="color red2"></div>=>4%<6%');
content.push('<p><div class="color red3"></div>=>6%<10%');
content.push('<p><div class="color red4"></div>=>10%<15%');
content.push('<p><div class="color red5"></div>=>15%<20%')
content.push('<p><img src="Smithfield Black.png" alt="Smithfield Logo" width ="120px">');
legend.innerHTML = content.join('');
legend.index = 1;
map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(legend);
var legend2 = document.createElement('div');
legend2.id = 'legend2';
var content2 = [];
content2.push("<h3>Smithfield Food's sales in Asda Stores</h3>");
content2.push('<p><img src="red-dot.png"><£1,000');
content2.push('<p><img src="yellow-dot.png">=>£1,000<£20,000');
content2.push('<p><img src="green-dot.png">=>£20,000<£40,000');
legend2.innerHTML = content2.join('');
legend2.index = 1;
map.controls[google.maps.ControlPosition.RIGHT_TOP].push(legend2);
var zoomToAddress = function() {
var address = document.getElementById('address').value;
geocoder.geocode({
address: address
}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
map.setZoom(10);
} else {
window.alert('Address could not be geocoded: ' + status);
}
});
};
google.maps.event.addDomListener(document.getElementById('search'), 'click', zoomToAddress);
google.maps.event.addDomListener(window, 'keypress', function(e) {
if (e.keyCode ==13) {
zoomToAddress();
}
});
google.maps.event.addDomListener(document.getElementById('reset'), 'click', function() {
map.setCenter(defaultCenter);
map.setZoom(defaultZoom);
layer.setOptions({
query: {
select: 'geometry',
from: '1hpGzmMBg8bDgPOGrAXvc0_QVLSBqQ0O5vpLbfUE'
}
});
});
}
// Open the info window at the clicked location
function windowControl(e, infoWindow, map) {
infoWindow.setOptions({
content: e.infoWindowHtml,
position: e.latLng,
pixelOffset: e.pixelOffset
});
infoWindow.open(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"></div>
<div>
<label>Enter an address:</label>
<input type="text" id="address" value="Leeds">
<input type="button" id="search" value="Search">
<input type="button" id="reset" value="Reset">
</div>
</body>
</html>
英国史密斯菲尔德食品公司
函数初始化(){
var=10;
var defaultCenter=new google.maps.LatLng(52.6500,1.2800)
var locationColumn='geometry'
var map=new google.maps.map(document.getElementById('map-canvas'){
中心:默认中心,
缩放:默认缩放,
mapTypeId:google.maps.mapTypeId.ROADMAP
});
var infoWindow=new google.maps.infoWindow();
//初始化第一层
var FirstLayer=new google.maps.FusionTablesLayer({
查询:{
选择“几何体”,
发件人:“1hpGzmMBg8bDgPOGrAXvc0_QVLSBQ0O5VPLBFUE”
},
地图:地图,
styleId:3,
模板ID:5,
suppressInfoWindows:true
});
google.maps.event.addListener(第一层,'click',函数(e){windowControl(e,infoWindow,map);
});
//初始化第二层
var SecondLayer=new google.maps.FusionTablesLayer({
查询:{
选择“邮政编码”,
发件人:“1RrCcRC-1vU0bfHQJTQWqToR-vllSsz9iKnI5WEk”
},
地图:地图,
styleId:2,
模板ID:2,
suppressInfoWindows:true
});
google.maps.event.addListener(第二层,'click',函数(e){windowControl(e,infoWindow,map);
});
var legend=document.createElement('div');
legend.id='legend';
var内容=[];
内容推送(“讲波兰语的人口密度”);
content.push('=>2%4%6%10%15%我得到一个“地理编码器未定义”错误。因为它未定义
解决此问题的一种方法是将其添加到全局范围(就在初始化函数之前):
或者你也可以按照它的方式来做,它在初始化函数中
var geocoder = new google.maps.Geocoder();