Google地方信息自动填充功能在iPhone上不起作用

时间:2019-01-20 12:55:23

标签: javascript google-api

我已经将Google Map自动完成功能添加到我网站的一部分中,并且可以正常工作,直到您尝试通过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);
            });

            }

0 个答案:

没有答案