2012-05-03 3 views
1

SetCenter 기능을 작동 시키려고 시도했지만 작동하지 않습니다. 여기 Google지도 SetCenter 기능이 작동하지 않습니다.

코드입니다 :

$("#searchclick").click(function(){ 

    var address = document.getElementById('searchbar').value; 
    var geocoder = new google.maps.Geocoder(); 

    geocoder.geocode({ 'address': address}, function(results, status) { 

     if (status == google.maps.GeocoderStatus.OK) { 

      var latitude2 = results[0].geometry.location.lat(); 

      var longitude2 = results[0].geometry.location.lng(); 

      var relocate = ("(" + latitude2 + ", " + longitude2 + ")"); 

      alert("setting the center to: " + relocate); 

      map.setCenter(relocate); 

      } //when status is OK 

     }); // geocode 

    }); 

경고가 제대로 반환 다음 setting the center to: (40.7143528, -74.0059731)

하지만이지도의 올바른 지점의 중심을하지 ...

어떤 아이디어 왜 ?

답변

5

세트 센터는 google.maps.LatLng 개체를 사용합니다.

var relocate = new google.maps.LatLng(latitude2, longitude2); 
alert("setting the center to: " + relocate); 
map.setCenter(relocate); 

참조 :

setCenter

LatLng

에 코드 변경
관련 문제