2014-10-31 3 views
1

고유 한 데이터 세트가있는지도가 있습니다. 외부 API에서 추가 정보를 불러 와서 사용자 정의 Google지도를 채 웁니다. 내가 구글에서 기능을 선택하고 자동을 사용하고Google지도 API - 현재지도에서 자동 완성 검색

그래서 특정 주소 또는 위치 정보에 대한 사용자 검색은, 그들은

그래서으로 (모든 데이터 포인트를 잃지 않고) 현재지도 에 확대하는 경우 이 기능은 출력이 올바른 : - :

console.log(defaultArea + ' ' + defaultLat + ' ' + defaultLng + ' ' + defaultZoom); 
London 51.5073509 -0.12775829999998223 6 

내 질문 쿼리 난 다음 얻을 수있는 방법이다현재지도에 있습니다.

나는 아직도 노력했다.

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

현재 JQUERY :

var defaultLat = 54 
defaultLng = -4, 
defaultZoom = 6, 
defaultArea = null; 

function searchFunct() { 
    var input = document.getElementById('location'); 
    var options = { 
     types: ['(regions)'], 
     componentRestrictions: { 
      country: 'uk' 
     } 
    }; 

    var autocomplete = new google.maps.places.Autocomplete(input, options); 

    google.maps.event.addListener(autocomplete, 'place_changed', function() { 
     var place = autocomplete.getPlace(); 
     document.getElementById('city2').value = place.name; 
     document.getElementById('cityLat').value = place.geometry.location.lat(); 
     document.getElementById('cityLng').value = place.geometry.location.lng(); 

     var citi = document.getElementById('city2').value; 
     var lati = document.getElementById('cityLat').value; 
     var longi = document.getElementById('cityLng').value; 

     defaultArea = citi; 
     defaultLat = lati; 
     defaultLng = longi; 
     defaultZoom = 6; 

     console.log(defaultArea + ' ' + defaultLat + ' ' + defaultLng + ' ' + defaultZoom); 

    }); 
} 
+0

지도의 코드는 어디에 있습니까? – geocodezip

답변

1

google.maps.LatLng 변수를지도 구글 내에서 선언하여 latitudelongitude을 정의하는 변수를하여 console.log

내가 한 모든이 아래에 다음을 추가합니다. 둘째, myOptions 객체를 선언하여 입력이 수행되는 위치를 정의합니다. 마지막으로, 모든 것을 map_canvas에 플롯하고 마커를 추가하십시오.

var latlng = new google.maps.LatLng(defaultLat, defaultLng); 
var myOptions = { 
    zoom: 11, 
    center: latlng, 
    mapTypeId: google.maps.MapTypeId.ROADMAP 
}; 

var map = new google.maps.Map(document.getElementById("map_canvas"), 
    myOptions); 

marker = new google.maps.Marker({ 
    position: latlng, 
    map: map, 
    title: 'Main map' 
}); 
관련 문제