-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlocation_picker.js
64 lines (48 loc) · 1.74 KB
/
location_picker.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
function initMap(lati , lngi) {
var map = new google.maps.Map(document.getElementById("map"), {
center: {
lat: lati- 0.1615,
lng: lngi + 0.4645
},
zoom: 8
});
var marker = new google.maps.Marker({
position: new google.maps.LatLng(lati, lngi),
map: map,
draggable: true
});
google.maps.event.addListener(marker, 'dragend', function () {
map.setCenter(marker.getPosition()); geocodePosition(marker.getPosition());
var lat = marker.getPosition().lat();
var lng = marker.getPosition().lng();
document.getElementById("lat").value = lat;
document.getElementById("lng").value = lng;
geocodePosition(marker.getPosition());
});
}
function geocodePosition(pos) {
geocoder = new google.maps.Geocoder();
geocoder.geocode({
latLng: pos
},
function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
//document.getElementById("address-label").innerHTML = results[0].formatted_address;
document.getElementById("address-label-title").innerHTML = results[0].formatted_address;
var add = results[0].formatted_address;
document.getElementById("address").value = add;
//var value = add.split(",");
//count = value.length;
//country = value[count - 1];
//state = value[count - 2];
//city = value[count - 3];
//document.getElementById("country").value = country;
//document.getElementById("state").value = state;
//document.getElementById("city").value = city;
} else {
//document.getElementById("address-label").value = 'cannot find';
document.getElementById("address-label-title").innerHTML = 'Cannot Find';
}
}
);
}