-1
입력 할 때 자동 완성 결과가 표시되지 않는 Google지도에 검색 창이 있습니다. 지도 자체가 표시되므로 내 API 자격 증명이 괜찮다고 생각합니다. 나는 뭔가 빠져있는 것처럼 보이지만 무엇을 알아낼 수 없어요! 검색 창에 입력하면 현재 아무것도Google지도 검색 창이 작동하지 않습니다.
<script src="https://maps.googleapis.com/maps/api/js?key=MYKEY&libraries=places&callback=initializeMap"
async defer></script>
function initializeMap() {
var mapOptions = {
center: { lat: 41.8369, lng: -87.6847 },
disableDefaultUI: true, // a way to quickly hide all controls
zoom: 8
};
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var input = document.getElementById('pac-input');
var searchBox = new google.maps.places.SearchBox(input);
map.controls[google.maps.ControlPosition.TOP].push(input);
map.addListener('bounds_changed', function() {
searchBox.setBounds(map.getBounds());
});
var markers = [];
searchBox.addListener('places_changed', function() {
var places = searchBox.getPlaces();
var place;
if (places.length == 0) {
return;
}
else {
place = places[0];
}
var lat = place.geometry.location.lat();
var lon = place.geometry.location.lng();
// Clear out the old markers.
markers.forEach(function (marker) {
marker.setMap(null);
});
markers = [];
// For each place, get the icon, name and location.
var bounds = new google.maps.LatLngBounds();
var marker = new google.maps.Marker({
map: map,
title: place.name,
draggable: true,
position: place.geometry.location
});
markers.push(marker);
if (place.geometry.viewport) {
// Only geocodes have viewport.
bounds.union(place.geometry.viewport);
} else {
bounds.extend(place.geometry.location);
}
map.fitBounds(bounds);
});
}
문제를 나타내는 [mcve]를 제공해주십시오. [누락 된 항목 (피들)을 추가하면 게시 된 코드가 작동합니다 (http://jsfiddle.net/geocodezip/9Lexv0xr/), 이는 문제가 누락되었거나 키가 잘못되었음을 의미합니다. 장소 API에 사용하도록 설정되었습니다. – geocodezip
당신이 옳습니다! Place API를 사용하도록 설정하지 않은 것으로 나타났습니다. 고맙습니다 – user1145998