-
Notifications
You must be signed in to change notification settings - Fork 1
/
googlemaps.js
68 lines (48 loc) · 1.72 KB
/
googlemaps.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
function initialize() {
/*var mapOptions = {
center: new google.maps.LatLng(0, 0),
zoom: 3
};
var map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);*/
usersRef.once('value', function(snapshot) {
snapshot.forEach(function(childSnapshot) {
console.log(childSnapshot.val().city);
$.ajax({
type: "GET",
url: "https://maps.googleapis.com/maps/api/geocode/xml?address=" + encodeURIComponent(childSnapshot.val().city) + "&key=AIzaSyCph8xf4Aw1o3-5HkTR_uOKIA_N4Ms5naY",
dataType: "xml",
success: processXML,
error: error
});
});
});
var mapOptions = {
center: new google.maps.LatLng(0, 0),
zoom: 2
};
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
function error() {
alert("Error");
}
function processXML(xml) {
var latitude = 0;
var longitude = 0;
$(xml).find("geometry").each(function() {
$(xml).find("location").each(function() {
latitude = parseFloat($(this).find("lat").text());
longitude = parseFloat($(this).find("lng").text());
});
});
var marker = new google.maps.Marker({
position: new google.maps.LatLng(latitude, longitude),
map: map,
title: "Something"
});
google.maps.event.trigger(map, 'resize');
}
}
google.maps.event.addDomListener(window, 'load', initialize);
setTimeout(function () {
$("#map-canvas").css("visibility", "visible");
}, 1000)