-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject.js
140 lines (109 loc) · 3.38 KB
/
project.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
var map;
var UserLocation;
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
function initialize() {
//var userLoc = new google.maps.LatLng(37.8759, -122.2806);
var AllCoffeeShops = [];
map = new google.maps.Map(document.getElementById('map-canvas'), {
center: UserLocation,
zoom: 12
});
var request = {
location: UserLocation,
radius: 500,
query: 'coffee'
};
infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
service.textSearch(request, callback);
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(UserLocationFinder, function() {
handleNoGeolocation(true);
});
} else {
// Browser doesn't support Geolocation
handleNoGeolocation(false);
}
directionsDisplay = new google.maps.DirectionsRenderer();
directionsDisplay.setMap(map);
function updateAllCoffee(results){
AllCoffeeShops = results;
}
function callback(results, status) {
updateAllCoffee(results);
console.log(AllCoffeeShops);
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
createMarker(results[i]);
//AllCoffeeShops.push(results[i]);
//console.log(AllCoffeeShops[i]);
}
}
}
}
function createMarker(place) {
var placeLoc = place.geometry.location;
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(place.name);
infowindow.open(map, this);
});
}
var UserLocationFinder = function(position) {
UserLocation = new google.maps.LatLng(position.coords.latitude,
position.coords.longitude);
var infowindow = new google.maps.InfoWindow({
map: map,
position: UserLocation,
content: 'Location found using HTML5.'
});
map.setCenter(UserLocation);
}
function handleNoGeolocation(errorFlag) {
if (errorFlag) {
var content = 'Error: The Geolocation service failed.';
} else {
var content = 'Error: Your browser doesn\'t support geolocation.';
}
var options = {
map: map,
position: new google.maps.LatLng(37.8759, -122.2806),
content: content
};
UserLocation = options.position;
var infowindow = new google.maps.InfoWindow(options);
map.setCenter(options.position);
}
function calcRoute() {
var start = UserLocation;
var end = "282 2nd Street 4th floor, San Francisco, CA 94105";
var waypts = [];
var checkboxArray = document.getElementById("waypoints");
for (var i = 0; i < checkboxArray.length; i++) {
if (checkboxArray.options[i].selected == true) {
waypts.push({
location:checkboxArray[i].value,
stopover:true
});
}
}
var selectedMODEbyUSER = document.getElementById("mode").value;
var request = {
origin: start,
destination: end,
waypoints: waypts,
//waypoints: [AllCoffeeShops[0]],
optimizeWaypoints: true,
travelMode: google.maps.TravelMode[selectedMODEbyUSER]
};
directionsService.route(request, function(result, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(result);
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);