3
我想將新加坡郵政編碼應用於護目鏡街道地圖。我在位置變量中傳遞郵政編碼,但當我更改郵編時,地圖位置不能更改。不知道我錯在哪裏。請幫忙。這裏是新加坡的一些郵編: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的標記的地圖?或者你想爲每個郵政編碼添加多個StreetView對象。郵政編碼的StreetView有什麼好處? – geocodezip
是的,我想要打開地圖的街道視圖(郵政編碼)。 – lumos