Я добавил автозаполнение карты Google в раздел моего сайта, и он работает нормально, пока вы не попытаетесь сделать это с iPhone. На самом деле, он действительно отображал карту, и автозаполнение работало нормально, но затем при следующем обновлении страницы оно перестало загружаться.
Вот как это работает на рабочем столе:
https://imgur.com/a/P9YL7RK
Вот скриншот с устройства Android:
https://imgur.com/a/fdOHddq
А вот скриншот с iPhone:
https://imgur.com/a/LTI9MXD
HTML:
<div class="glocation">
<div class="locationContainer">
<input id="locationInput" type="text" placeholder="Enter the venue's name or address"
class="form-control">
</div>
<div id="map"></div>
<div id="infowindow-content">
<img src="" width="16" height="16" id="place-icon">
<span id="place-name" class="title"></span><br>
<span id="place-address"></span>
</div>
</div>
JAVASCRIPT:
// GOOGLE LOCATION
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {
lat: 35.9375,
lng: 14.3754
},
zoom: 12
});
var card = document.getElementById('glocation');
var input = document.getElementById('locationInput');
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(card);
var autocomplete = new google.maps.places.Autocomplete(input);
// Bind the map's bounds (viewport) property to the autocomplete object,
// so that the autocomplete requests use the current map bounds for the
// bounds option in the request.
autocomplete.bindTo('bounds', map);
// Set the data fields to return when the user selects a place.
autocomplete.setFields(
['address_components', 'geometry', 'icon', 'name']);
var infowindow = new google.maps.InfoWindow();
var infowindowContent = document.getElementById('infowindow-content');
infowindow.setContent(infowindowContent);
var marker = new google.maps.Marker({
map: map,
anchorPoint: new google.maps.Point(0, -29)
});
autocomplete.addListener('place_changed', function () {
infowindow.close();
marker.setVisible(false);
var place = autocomplete.getPlace();
if (!place.geometry) {
// User entered the name of a Place that was not suggested and
// pressed the Enter key, or the Place Details request failed.
window.alert("No details available for input: '" + place.name + "'");
return;
} else {
locationSelected = true;
}
// If the place has a geometry, then present it on a map.
if (place.geometry.viewport) {
map.fitBounds(place.geometry.viewport);
} else {
map.setCenter(place.geometry.location);
map.setZoom(17); // Why 17? Because it looks good.
}
marker.setPosition(place.geometry.location);
marker.setVisible(true);
var address = '';
if (place.address_components) {
address = [
(place.address_components[0] && place.address_components[0].short_name || ''),
(place.address_components[1] && place.address_components[1].short_name || ''),
(place.address_components[2] && place.address_components[2].short_name || '')
].join(' ');
}
infowindowContent.children['place-icon'].src = place.icon;
infowindowContent.children['place-name'].textContent = place.name;
infowindowContent.children['place-address'].textContent = address;
infowindow.open(map, marker);
});
}