-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy pathajax_daerah.js
142 lines (134 loc) · 4.33 KB
/
ajax_daerah.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
var ajaxku=buatajax();
function ajaxkota(id){
var url="select_daerah.php?prop="+id+"&sid="+Math.random();
ajaxku.onreadystatechange=stateChanged;
ajaxku.open("GET",url,true);
ajaxku.send(null);
}
function ajaxkec(id){
var url="select_daerah.php?kab="+id+"&sid="+Math.random();
ajaxku.onreadystatechange=stateChangedKec;
ajaxku.open("GET",url,true);
ajaxku.send(null);
}
function ajaxkel(id){
var url="select_daerah.php?kec="+id+"&sid="+Math.random();
ajaxku.onreadystatechange=stateChangedKel;
ajaxku.open("GET",url,true);
ajaxku.send(null);
}
function buatajax(){
if (window.XMLHttpRequest){
return new XMLHttpRequest();
}
if (window.ActiveXObject){
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
function stateChanged(){
var data;
if (ajaxku.readyState==4){
data=ajaxku.responseText;
if(data.length>=0){
document.getElementById("kota").innerHTML = data
}else{
document.getElementById("kota").value = "<option selected>Pilih Kota/Kab</option>";
}
document.getElementById("kab_box").style.display='table-row';
document.getElementById("kec_box").style.display='none';
document.getElementById("kel_box").style.display='none';
document.getElementById("lat_box").style.display='none';
document.getElementById("lng_box").style.display='none';
}
}
function stateChangedKec(){
var data;
if (ajaxku.readyState==4){
data=ajaxku.responseText;
if(data.length>=0){
document.getElementById("kec").innerHTML = data
}else{
document.getElementById("kec").value = "<option selected>Pilih Kecamatan</option>";
}
document.getElementById("kec_box").style.display='table-row';
document.getElementById("kel_box").style.display='none';
document.getElementById("lat_box").style.display='none';
document.getElementById("lng_box").style.display='none';
}
}
function stateChangedKel(){
var data;
if (ajaxku.readyState==4){
data=ajaxku.responseText;
if(data.length>=0){
document.getElementById("kel").innerHTML = data
}else{
document.getElementById("kel").value = "<option selected>Pilih Kelurahan/Desa</option>";
}
document.getElementById("kel_box").style.display='table-row';
document.getElementById("lat_box").style.display='none';
document.getElementById("lng_box").style.display='none';
}
}
var map;
var geocoder;
var marker;
var markersArray = [];
function initialize() {
geocoder = new google.maps.Geocoder();
var myLatlng =new google.maps.LatLng(-6.176655999999999, 106.83058389999997);
var mapOptions = {
center: myLatlng,
zoom: 14
};
map = new google.maps.Map(document.getElementById('map-canvas'),mapOptions);
marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Jakarta'
});
markersArray.push(marker);
google.maps.event.addListener(marker,"click",function(){});
}
function clearOverlays() {
for (var i = 0; i < markersArray.length; i++ ) {
markersArray[i].setMap(null);
}
markersArray.length = 0;
}
function showCoordinate(){
var prop = document.getElementById("prop");
var kab = document.getElementById("kota");
var kec = document.getElementById("kec");
var kel = document.getElementById("kel");
var s = kel.options[kel.selectedIndex].text
+', '
+kec.options[kec.selectedIndex].text;
s2= s
+', '
+kab.options[kab.selectedIndex].text
+', '
+prop.options[prop.selectedIndex].text;
geocoder.geocode( { 'address': s}, function(results, status) {
document.getElementById("lat_box").style.display='table-row';
document.getElementById("lng_box").style.display='table-row';
if (status == google.maps.GeocoderStatus.OK) {
clearOverlays();
var position=results[0].geometry.location;
document.getElementById("lat").value=position.lat();
document.getElementById("lng").value=position.lng();
map.setCenter(results[0].geometry.location);
marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
title:s2
});
markersArray.push(marker);
google.maps.event.addListener(marker,"click",function(){});
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);