私は検索フィールドを持つGoogleマップを使用しており、ユーザーがその検索フィールドに入力すると、マップ内の場所が変更されますが、ユーザーが検索フィールドに場所をコピーして貼り付けた場合、場所も変更する必要がありますが、現在はそうですコピーペーストイベントでは変更されません。
function centerLocation() {
var zoom = 6;
var position = {
coords: {
latitude: 77.040,
longitude: 2.908
}
};
var map = new google.maps.Map(document.getElementById('map'), {});
// Create the search box and link it to the UI element.
var input = document.getElementById('pac-input');
var searchBox = new google.maps.places.SearchBox(input);
map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
// Bias the SearchBox results towards current map's viewport.
map.addListener('bounds_changed', function() {
searchBox.setBounds(map.getBounds());
});
searchBox.addListener('places_changed', function() {
var places = searchBox.getPlaces();
if (places.length == 0) {
return;
}
console.log(places);
if (places.length == 1) {
var place = places[0];
if (place.geometry.viewport) {
// Only geocodes have viewport.
map.fitBounds(place.geometry.viewport);
} else {
map.setCenter(place.geometry.location);
}
} else {
// For each place, get the icon, name and location.
var bounds = new google.maps.LatLngBounds();
places.forEach(function(place) {
if (!place.geometry) {
console.log("Returned place contains no geometry");
return;
}
if (place.geometry.viewport) {
// Only geocodes have viewport.
bounds.union(place.geometry.viewport);
} else {
bounds.extend(place.geometry.location);
}
map.fitBounds(bounds);
});
}
});
}
google.maps.event.addDomListener(window, "load", initialize);
function initialize() {
centerLocation();
}
html,
body,
#map-container2,
#map {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?libraries=places&key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk&"></script>
<div id="map-container2" class="">
<input id="pac-input" class="controls" type="text" placeholder="Ville - Recherche">
<div id="map"></div>
</div>