-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
73 lines (70 loc) · 2.32 KB
/
script.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
var map;
var geocoder;
async function initMap() {
var rns = {lat:12.902351, lng:77.518605};
const { Map } = await google.maps.importLibrary("maps");
map = new Map(document.getElementById("map"), {
zoom: 15,
center : rns,
});
var cdata = JSON.parse(document.getElementById('data').innerHTML);
console.log(cdata);
geocoder = new google.maps.Geocoder();
codeAddress(cdata);
var allData = JSON.parse(document.getElementById('allData').innerHTML);
showJobs(allData);
}
function showJobs(allData){
Array.prototype.forEach.call(allData, function(data){
var contentString = ' ' + '<h1 style="font-weight:bold;">'+data.name + '</h1>' +'<br>' + '<p style="font-size:1rem;">' + data.info + '</p>' +'<br>' + '<a href="'+data.site+'" style="font-weight: bold;text-decoration: underline;">'+"Website"+'</a>';
var infoWind = new google.maps.InfoWindow({
content: contentString,
});
var marker = new google.maps.Marker({
position: new google.maps.LatLng(data.lat, data.lng),
map: map
});
marker.addListener('click', function(){
// infoWind.setContent(content);
infoWind.open(map, marker);
})
})
}
function codeAddress(cdata) {
Array.prototype.forEach.call(cdata, function(data){
var address = data.name + ' ' + data.address;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == 'OK') {
map.setCenter(results[0].geometry.location);
// console.log(results[0].geometry.location);
// alert(map.getCenter().lat())
var points = {};
points.id = data.id;
points.lat = map.getCenter().lat();
points.lng = map.getCenter().lng();
updateLatLngJobs(points);
} else {
if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
nextAddress--;
delay++;
} else {
var reason="Code "+status;
var msg = 'address="' + search + '" error=' +reason+ '(delay='+delay+'ms)<br>';
document.getElementById("messages").innerHTML += msg;
}
}
});
});
}
function updateLatLngJobs(points){
$.ajax({
url:"action.php",
method: "post",
data: points,
success: function(res){
console.log(res);
}
})
// console.log(points)
}
initMap();