Я пытаюсь получить первый элемент, который будет выбран в поиске, но когда я набираю что-то и нажимаю ввод, я получаю ошибку.
Я устал использовать новый google.maps.searchbar, но все еще не могу отразить это.
function initMap() {
@if(Request::path()=='owner/add-property')
dragMap();
@endif
var input = document.getElementById('pac-input');
var autocomplete = new google.maps.places.Autocomplete(input);
var firstResult = $(".pac-container .pac-item:first").text();
$("input").focusin(function () {
$(document).keypress(function (e) {
if (e.which == 13) {
//alert("enter"); return false;
//var places1 = new google.maps.places.Autocomplete(document.getElementById('pac-input'));
var places2 = new google.maps.places.SearchBox(document.getElementById('pac-input'));
var place = places.getPlace();
var address = place.formatted_address;
var latitude = place.geometry.location.lat();
var longitude = place.geometry.location.lng();
var mesg = "Address: " + address;
mesg += "\nLatitude: " + latitude;
mesg += "\nLongitude: " + longitude;
//alert(mesg);
var html_data = '<input type="hidden" name="lat" value="'+latitude+'"/>';
html_data += '<input type="hidden" name="lng" value="'+longitude+'"/>';
html_data += '<input type="hidden" name="formatted_address" value="'+address+'"/>';
$("#set_location").html(html_data);
$("#search_location").html(html_data);
}
});
});
google.maps.event.addDomListener(window, 'load', function () {
var places = new google.maps.places.Autocomplete(document.getElementById('pac-input'));
google.maps.event.addListener(places, 'place_changed', function () {
var place = places.getPlace();
var address = place.formatted_address;
var latitude = place.geometry.location.lat();
var longitude = place.geometry.location.lng();
var mesg = "Address: " + address;
mesg += "\nLatitude: " + latitude;
mesg += "\nLongitude: " + longitude;
//alert(mesg);
var html_data = '<input type="hidden" name="lat" value="'+latitude+'"/>';
html_data += '<input type="hidden" name="lng" value="'+longitude+'"/>';
html_data += '<input type="hidden" name="formatted_address" value="'+address+'"/>';
$("#set_location").html(html_data);
$("#search_location").html(html_data);
});
});
@if(Request::path()=='short-term' || Request::path()=='search-property')
initMaps();
@endif
@if(Request::path()=='contact')
contact_map();
@endif ,
Я получаю следующую ошибку. Неопределенный индекс: formatted_address