0
이것은 내가 작성하려고 시도한 첫 번째 자바 스크립트이지만 많은 행운이 없습니다.Jquery 초보자 - 지오 코더가 결과를 반환하지 않음
지오 주소를 우리는 자기 암시를 클릭 에서 이미 결과가없는 경우 검색 버튼을 클릭하여 autosuggested 위치 또는 을 클릭하여 다음 중 하나를이 스크립트가해야 할 일이다. 그런 다음 양식을 제출하십시오.
나는 행운이별로 없다. 내가 뭘 할지라도 예외에 관해서 불평하기 때문에 나는 스크립트에서 내 브래킷을 망쳤다. 내가 잘못 갈 곳 LINK
geocode();
// SET COOKIE FOR TESTING PURPOSES
$.cookie("country", "US");
// GEOCODE FUNCTION
function geocode() {
var coded = false;
var input = document.getElementById('loc');
var options = {
types: ['geocode']
};
var country_code = $.cookie('country');
if (country_code) {
options.componentRestrictions = {
'country': country_code
};
}
var autocomplete = new google.maps.places.Autocomplete(input, options);
google.maps.event.addListener(autocomplete, 'place_changed', function() {
processLocation();
});
// ON SUBMIT - WORK OUT IF WE ALREADY HAVE THE RESULTS FROM AUTOCOMPLETE FUNCTION
$('#searchform').on('submit', function(e) {
e.preventDefault();
if(coded = false;) {
processLocation();
}
else {
$('#searchform').submit();
}
});
// CHECK TO SEE IF INPUT HAS CHANGED SINCE BEING GEOCODED
// IF "CODED" VAR IS FALSE THEN WE WILL GEOCODE WHEN SEARCH BUTTON HIT
$("#loc").bind("change paste keyup", function() {
var coded = false;
});
};
// GEOCODE THE LOCATION
function processLocation(){
var geocoder = new google.maps.Geocoder();
var address = document.getElementById('loc').value;
$('#searchform input[type="submit"]').attr('disabled', true);
geocoder.geocode({
'address': address
},
// RESULTS - STORE COORDINATES IN FIELDS OR ERROR IF NOT SUCCESSFUL
function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var coded = true;
$('#lat').val(results[0].geometry.location.lat());
$('#lng').val(results[0].geometry.location.lng());
} else {
var coded = false;
$('#searchform input[type="submit"]').attr('disabled', false);
alert("We couldn't find this location")
}
});
}
사람이 볼 수
이 내 코드?
Ps 내 첫 번째 스크립트이기 때문에 지식이있는 사람이라면 스크립트 디자인면에서 좋지 않은 선택을했는지 알 수 있다면 정말 고맙겠습니다. 가능한 한 깔끔하게 코딩 된 첫 번째 스크립트.