2013-03-09 5 views
1

하루 종일 검색하고 수많은 코드 메소드를 사용해도 Google지도를 올바르게 가운데 맞추기 및 확대/축소하는 데 문제가 있습니다.Google지도 v3 - 경계를 마커 중심으로 설정

누군가 내 코드에서 잘못하고있는 것을 분명히 지적 할만큼 친절한 지 궁금합니다. 모든 것이 v2에서 잘 돌아 갔지만 Im은 v3으로 업데이트하는 데 어려움이 있습니다. 정보 지도에 대한

은 훨씬 더 큰 PHP 애플리케이션의 작은 부분이며, 다음 & 긴 맵 매개 변수가 이미 주요 음식물에 사용 선언 된 다른 방법에 의해 얻어졌다 LAT 필요 : -

var myDestination=new google.maps.LatLng(e_lat,e_long); 
var myHome=new google.maps.LatLng(h_lat,h_long); 

확대/축소와 가운데를 제외한 모든 것이 정상적으로 작동하는 것 같습니다. 다음과 같이 문제있는 코드는 다음과 같습니다 -

function initialize() 
{ 

// set the map properties 
var mapProp = { 
    center:myHome, 
    zoom:12, 
    mapTypeId:google.maps.MapTypeId.ROADMAP 
    }; 

var map=new google.maps.Map(document.getElementById("googleMap"),mapProp); 

// set the home marker 
var marker_home=new google.maps.Marker({ 
    position:myHome, 
    icon:'house.png' 
    }); 

    marker_home.setMap(map); 

//set the destination marker 
var marker_destination=new google.maps.Marker({ 
    position:myDestination, 
    icon:'flag_red.png' 
    }); 

    marker_destination.setMap(map); 



//google polyline between the 2 points 
var myPolyline = [myDestination,myHome]; 
var directPath = new google.maps.Polyline({ 
    path:myPolyline, 
    strokeColor:"#0000FF", 
    strokeOpacity:0.8, 
    strokeWeight:2 
}); 

directPath.setMap(map); 


// Make an array of the LatLng's of the markers you want to show 
var LatLngList = array (new google.maps.LatLng (e_lat,e_long), new google.maps.LatLng (h_lat,h_long)); 
// Create a new viewpoint bound 
var bounds = new google.maps.LatLngBounds(); 
// Go through each... 
for (var i = 0, LtLgLen = LatLngList.length; i < LtLgLen; i++) { 
// And increase the bounds to take this point 
bounds.extend (LatLngList[i]); 
} 
// Fit these bounds to the map 
map.fitBounds (bounds); 

} 

google.maps.event.addDomListener(window, 'load', initialize); 

TIA 정의되지 않은 도움 :) 코드 "배열"에서

+1

를 사용해야합니까? 자바 스크립트 오류가 발생합니까? 당신은 단지 2 점을 가지고 있기 때문에, 그것은 루프없이 작동해야합니다. 문제가있는지도에 대한 링크를 제공 할 수 있습니까 (아니면 jsfiddle을 만들 수 있습니까)? – geocodezip

+0

fitBounds가 제대로 작동하지 않아서 두 지점 사이를 정확하게 중심에 있지 않다는 점을 표시하는 것 같습니다. 당신은 내가 교체 한 응답을 http://jsfiddle.net/klaw/tQf9n/3/ – klaw

답변

1

을 위해. jsFiddle을 참조하십시오.

var LatLngList = array (new google.maps.LatLng (e_lat,e_long), new google.maps.LatLng (h_lat,h_long)); 

당신은이 일을 무엇

var LatLngList = new Array(new google.maps.LatLng...) 

또는

var LatLngList = [new google.maps.LatLng...] 
+0

감사합니다 VAR LatLngList = [ \t \t \t [새은 google.maps.LatLng (e_lat, e_long), \t \t \t [new google.maps.LatLng (h_lat, h_long)] \t \t \t]; 그러나 여전히 동일한 동작을 나타내지 만 경계 내에서 2 점을 제한하지 않으며지도가 홈 및 대상 간의 정확한 줌 또는 센터링 중간 지점에 맞지 않습니다. :/당신은 .. – klaw

+0

'VAR LatLngList = [새로운은 google.maps.LatLng (e_long e_lat), 새로운은 google.maps.LatLng (h_lat, h_long)]' HTTP 지금까지 조언을 도움에 대한 가 감사합니다 : //jsfiddle.net/tQf9n/4/ –

+0

예! 그러한 n00b를 도와 주셔서 대단히 감사합니다. 그것은 그것을 분류하고 지금 그것의 센터를 완벽하게합니다. – klaw

관련 문제