2013-01-12 2 views
3

고글 거리지도에 싱가포르 우편 번호를 적용하려고합니다. 위치 변수에 우편 번호를 전달하고 있지만 우편 번호를 변경하면지도 위치가 바뀌지 않습니다. 내가 틀린 곳을 모른다. 도와주세요. 여기에 싱가포르의 일부 우편 번호는 다음과 같습니다 189,969은 189,927 여기 mapgoogle.maps.Map -object 될 수 있도록 코드를 수정 내 코드Google지도 스트리트 뷰 (우편 번호 포함)

<!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> 
+0

map은 StreetViewPanorama 개체입니다. setCenter 메소드가 없습니다. 코드의 디자인을 재고해야합니다. 위치의 StreetView (우편 번호)를 여는 마커가있는지도를 원하십니까? 또는 각 우편 번호에 대해 여러 StreetView 객체를 원하십니까? 우편 번호 StreetView의 장점은 무엇입니까? – geocodezip

+0

예 위치 (스트리트 뷰)의 StreetView를 여는 마커가있는지도를 원합니다. – lumos

답변

3

입니다.

당신이 (예를 들어 geocoder.geocode()의 콜백 내부)지도의 스트리트 뷰를 표시 할

다음을 수행해야합니다

  1. 은 스트리트 뷰의 가시성을 설정 스트리트 뷰
  2. 의 위치를 ​​설정

예 :

map.streetView.setPosition(results[0].geometry.location); 
map.streetView.setVisible(true); 

데모 : http://jsfiddle.net/doktormolle/7J4G6/

스트리트 뷰를 제어 할 수있는 옵션이 더 있습니다 (예 : 주어진 위치에 대해 streetview를 사용할 수 있는지 확인하는 것이 좋습니다.)하지만 위의 두 줄은 최소한의 요구 사항입니다.