0
숫자 주소 생성기를 생성하고 버튼 클릭시 ajax를 통해 수행 할 수있는 json 형식 출력을 얻어야합니다. 하지만 어떻게 동적으로 자동 완성을 생성하고 물건을 별도로 얻을 Google API를 사용할 수 없어요.동적으로 주소 자동 완성 API를 생성하는 방법
필자는이 바이올린에 첨부 된 것과 정확히 같은 유형의 디자인을 보여줄 필요가 있습니다.
initialize();
var placeSearch, autocomplete;
var componentForm = {
street_number: 'short_name',
route: 'long_name',
locality: 'long_name',
administrative_area_level_1: 'short_name',
country: 'long_name',
postal_code: 'short_name'
};
function initialize() {
autocomplete = new google.maps.places.Autocomplete(
/** @type {HTMLInputElement} */(document.getElementById('autocomplete')),
{ types: ['geocode'] });
google.maps.event.addListener(autocomplete, 'place_changed', function() {
fillInAddress();
});
}
function fillInAddress() {
var place = autocomplete.getPlace();
for (var component in componentForm) {
document.getElementById(component).value = '';
document.getElementById(component).disabled = false;
}
for (var i = 0; i < place.address_components.length; i++) {
var addressType = place.address_components[i].types[0];
if (componentForm[addressType]) {
var val = place.address_components[i][componentForm[addressType]];
document.getElementById(addressType).value = val;
}
}
}
function geolocate() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var geolocation = new google.maps.LatLng(
position.coords.latitude, position.coords.longitude);
autocomplete.setBounds(new google.maps.LatLngBounds(geolocation,
geolocation));
});
}
}
현재 나는 3 형식을 추가했습니다,하지만 난 내가 JQuery와 APPEND를 사용하여 수행 할 수 있습니다 생각 "양식을 추가"버튼을 통해 추가해야합니다. 그러나 Google 자동 완성에서 작동하도록 만드는 방법은 무엇입니까? 여러 형태의 관리를 다시 사용하려면
감사
jsFiddle을 편집하여'# addForm' 클릭 함수에 for 루프를 추가했습니다. 또한 css 클래스를'data-component' 속성으로 대체하여 아약스 호출로 보낼 데이터를 작성합니다. '# sendData' 클릭 기능을 사용하여 ajax 호출을 수행하십시오. URL을 지정하고 데이터 형식을 수정할 필요가 있습니다 (데이터가 생성 된 것을 설명하기 위해 양식 뒤에 쓰여짐). 그리고 그 대답을 받아들이는 것을 잊지 마세요! – rd3n
사실 '주문 배송'을 클릭하면 양식이 포함 된 '주문 번호 1'과 모든 필드 및 자동 완성이 초기화 된 모달이 필요합니다. 그리고 '폼 추가'를 클릭하면 두 번째 폼이 초기화 된 'Order # 2'가 추가됩니다. 그렇다면 스크립트를 수정해야합니다. 그게 네가하고 싶은 일인지 확인해, 오늘 밤이나 내일 도울거야. 그럼 너 혼자 계속해야 겠어, 난 네 일을 다 할 수 없어. D – rd3n