【发布时间】:2013-01-12 06:10:47
【问题描述】:
我正在尝试在 goggle 街道地图中应用新加坡邮政编码。我在位置变量中传递邮政编码,但是当我更改邮政编码时,地图位置无法更改。不知道我哪里错了。请帮忙。这是新加坡的一些邮政编码:189969、189927 这是我的代码
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title></title>
<script type='text/javascript' src='mootools-core-1.3.2.js'></script>
<link rel="stylesheet" type="text/css" href="/css/normalize.css">
<style type='text/css'>
#map_canvas {
background:#ccc;
height:400px;
width:100%;
}
</style>
<script type='text/javascript'>//<![CDATA[
window.addEvent('load', function() {
var map;
var geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(1.280095,103.850949);
var panoramaOptions = {
position: latlng,
};
map = new google.maps.StreetViewPanorama(document.getElementById('map_canvas'),panoramaOptions);
var locations = ['189969'];
function codeAddress(locations) {
for (i = 0; i < locations.length; i++) {
geocoder.geocode( { 'address': locations[i]}, 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
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
}
codeAddress(locations);
});//]]>
</script>
</head>
<body>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<div id="map_canvas">map</div>
</body>
</html>
【问题讨论】:
-
地图是 StreetViewPanorama 对象。它没有 setCenter 方法。您需要重新考虑代码的设计。您是否想要一张带有可打开该位置街景的标记的地图(邮政编码?)?或者您是否希望每个邮政编码有多个 StreetView 对象。邮政编码的街景有什么用?
-
是的,我想要一张带有标记的地图,可以打开该位置的街景(邮政编码)。