如何獲得搜索用戶的長版信用卡?我已經設置了這個jsfiddle,除了第一次搜索,一切都正常,當人們搜索'紐約'時,他們會在地圖上得到一個標記,當他們拖動標記時,我得到長拖尾,但是,我怎麼能起初的搜索長拖鞋?從谷歌地圖的搜索框中獲取長時間空檔API
https://jsfiddle.net/x1a9z5t5/
function init() {
var map = new google.maps.Map(document.getElementById('map-canvas'), {
center: {
lat: 40.730610,
lng: -73.935242
},
zoom: 12
});
var searchBox = new google.maps.places.SearchBox(document.getElementById('adress-input'));
map.controls[google.maps.ControlPosition.TOP_CENTER].push(document.getElementById('adress-input'));
google.maps.event.addListener(searchBox, 'places_changed', function() {
searchBox.set('map', null);
var places = searchBox.getPlaces();
var bounds = new google.maps.LatLngBounds();
var i, place;
for (i = 0; place = places[i]; i++) {
(function(place) {
var marker = new google.maps.Marker({
position: new google.maps.LatLng(40.730610, -73.935242),
draggable: true,
position: place.geometry.location
});
marker.bindTo('map', searchBox, 'map');
google.maps.event.addListener(marker, 'map_changed', function() {
if (!this.getMap()) {
this.unbindAll();
}
});
bounds.extend(place.geometry.location);
google.maps.event.addListener(marker, 'dragend', function(evt) {
document.getElementById('long-lat').innerHTML = evt.latLng.lat().toFixed(3) + " " + evt.latLng.lng().toFixed(3);
});
}(place));
}
map.fitBounds(bounds);
searchBox.set('map', map);
map.setZoom(Math.min(map.getZoom(), 12));
});
}
google.maps.event.addDomListener(window, 'load', init);