JSON 파일의 마커를로드하고 페이지가 처음로드 될 때이를 표시하는 Google지도를 만들었습니다. 이 기능 비트는 올바르게 작동합니다. 그러나 내 페이지에는 양식도 포함되어 있으며 양식을 제출하여지도를 업데이트하면 getJSON 요청을 다시 실행하고 싶습니다. 이것은 내가 일할 수없는 비트입니다. 누구든지 내가 뭘 잘못하고 있는지 알 수 있니?양식에 Google지도 다시로드하기 제출
<!doctype html>
<html lang="en">
<head>
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="jquery.ui.map.js"></script>
<script>
// convert form parameters sent using getJSON method to JSON
$.fn.serializeObject = function() {
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name]) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};
$(function() {
// method to initialise map
function initialise() {
$('#map_canvas').gmap({
'disableDefaultUI':true, 'callback': function() {
var self = this;
$.getJSON('http://localhost:8888/googlemaps/demo.json',
$('#filter').serializeObject(),
function(data) {
$.each(data.markers, function(i, marker) {
self.addMarker({ 'position': new google.maps.LatLng(marker.latitude, marker.longitude), 'bounds':true }).click(function() {
self.openInfoWindow({ 'content': marker.content }, this);
});
});
}
);
}
});
}
// initial map on page load
initialise();
// reinitialise map on form submit
$('#filter').submit(function(e) {
initialise();
e.preventDefault();
});
});
</script>
</head>
<body>
<form id="filter">
<select name="foo" id="foo">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<select name="bar" id="bar">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<input type="submit">
</form>
<div id="map_canvas" style="height:400px; width:100%;"></div>
</body>
</html>