내 asp.net 프로젝트에서 google maps를 사용하고 있습니다. 일부 주소를 입력하면 제안 사항이 표시되고 그 중 하나를 선택하면 해당 주소와 관련된지도가 표시됩니다. 이것은 잘 작동합니다. 하지만 그 사용자 유형을 1 페이지의 텍스트 상자에 입력하고 그 입력을 받아 페이지 2의지도 텍스트 상자와 2 페이지의 주소와 관련된지도를 채우려합니다. 여기두 번째 페이지에 Google지도 표시
난 당신이 해시 태그와 다른 페이지 (또는 같은 페이지)에 변수를 보낼 수 있습니다 그것을
$(document).ready(function() {
// Empty the value on page load
$("#formattedAddress").val("");
// variable to indicate whether or not enter has been pressed on the input
var enterPressedInForm = false;
var input = document.getElementById("inputName");
var options = {
componentRestrictions: {country: 'uk'}
};
autocomplete = new google.maps.places.Autocomplete(input, options);
$("#formName").submit(function(e) {
// Only submit the form if information has been stored in our hidden input
return $("#formattedAddress").val().length > 0;
});
$("#inputName").bind("keypress", function(e) {
if(e.keyCode == 13) {
// Note that simply triggering the 'place_changed' event in here would not suffice, as this would just create an object with the name as typed in the input field, and no other information, as that has still not been retrieved at this point.
// We change this variable to indicate that enter has been pressed in our input field
enterPressedInForm = true;
}
});
// This event seems to fire twice when pressing enter on a search result. The first time getPlace() is undefined, and the next time it has the data. This is why the following logic has been added.
google.maps.event.addListener(autocomplete, 'place_changed', function() {
// If getPlace() is not undefined (so if it exists), store the formatted_address (or whatever data is relevant to you) in the hidden input.
if(autocomplete.getPlace() !== undefined) {
$("#formattedAddress").val(autocomplete.getPlace().formatted_address);
}
// If enter has been pressed, submit the form.
if(enterPressedInForm) {
$("#formName").submit();
}
});
});
감사합니다, 아시프 하미드