This repository was archived by the owner on May 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathGeolocation.js
75 lines (63 loc) · 2.1 KB
/
Geolocation.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
// Geolocation functionality for the little finder project
// using Google Maps JavaScript API
// ---- Get current location -------
// TODO: add file to store locations
var locations = [];
function initMap() {
var infoWindow;
var uluru = {lat: -25.363, lng: 131.044};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 4,
center: uluru
});
infoWindow = new google.maps.InfoWindow;
// Create an array of alphabetical characters used to label the markers.
var labels = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
var marker = new google.maps.Marker({
position: pos,
map: map,
title: "Location found!"
});
map.setZoom(14);
map.setCenter(pos);
var data = {"locations":[{
}]};
data.locations.push({
lat: position.coords.latitude,
lng: position.coords.longitude
});
// txt = JSON.stringify(data);
console.log(data)
}, function() {
handleLocationError(true);
});
} else {
// Browser doesn't support Geolocation
handleLocationError(false);
}
}
function handleLocationError(browserHasGeolocation, pos) {
alert(browserHasGeolocation ?
'Error: The Geolocation service failed.' :
'Error: Your browser doesn\'t support geolocation.');
}
/*
// Add some markers to the map.
var markers = locations.map(function(location, i) {
console.log('executing markers..., location: ', location);
return new google.maps.Marker({
position: location,
label: labels[i % labels.length]
});
});
// Add a marker clusterer to manage the markers.
var markerCluster = new MarkerClusterer(map, markers,
{imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'});
*/
//TODO: Add event listener for the button