-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPracticeGPS.js
More file actions
104 lines (82 loc) · 2.32 KB
/
PracticeGPS.js
File metadata and controls
104 lines (82 loc) · 2.32 KB
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
var marker;
var defaultMarker = {
animation: google.maps.Animation.DROP,
draggable: true
}
var currentLocation={};
var map;
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(
40.724531899999995,
-73.7971586),
zoom: 16,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
currentLocation = loadLocation(setMarker(marker), function(error){
switch(error.code) {
case error.PERMISSION_DENIED:
console.log("User denied permission.");
break;
case error.POSITION_UNAVAILABLE:
console.log("Geolocation/GPS unavailable.");
break;
case error.TIMEOUT:
console.log("Geolocation request timed out.");
break;
case error.UNKNOWN_ERROR:
console.log("Something wack happened.");
break;
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
function setMarker(marker){
/*
var contentString = "<div class=\"align-center\"> <button class=\"align-center\" type=\"button\">Drop a Crumb</button> </div>"
var infowindow = new google.maps.InfoWindow({
content: contentString
});
*/
return function(latlng){
var pos = new google.maps.LatLng(latlng.latitude, latlng.longitude);
marker = new google.maps.Marker({
map: map,
position: pos,
animation: defaultMarker.animation,
draggable: defaultMarker.draggable
});
map.panTo(marker.getPosition());
google.maps.event.addListener(marker, 'clicked', function(){
console.log("hello there");
toggleBounce(marker);
//infowindow.open(map, marker);
})
google.maps.event.addListener(marker, 'dragend', function(){
map.panTo(marker.getPosition());
});
}
};
function toggleBounce(marker) {
if (marker.getAnimation() != null) {
marker.setAnimation(null);
} else {
marker.setAnimation(google.maps.Animation.BOUNCE);
}
}
//Callbacks
function loadLocation (callback, error){
latlng = currentLocation;
function getLocation(pos){
latlng["latitude"] = pos.coords.latitude;
latlng["longitude"] = pos.coords.longitude;
callback(latlng);
}
var load = function() {
if (navigator.geolocation) {
console.log("Loading location now....");
navigator.geolocation.getCurrentPosition(getLocation, error);
}
}();
};