-
Notifications
You must be signed in to change notification settings - Fork 1
/
geo.js
69 lines (56 loc) · 1.98 KB
/
geo.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
function initialize() {
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(handle_geolocation_query, handle_errors);
}
function handle_errors(error)
{
switch(error.code)
{
case error.PERMISSION_DENIED: alert("user did not share geolocation data");
break;
case error.POSITION_UNAVAILABLE: alert("could not detect current position");
break;
case error.TIMEOUT: alert("retrieving position timedout");
break;
default: alert("unknown error");
break;
}
}
function handle_geolocation_query(position){
// alert('Lat: ' + position.coords.latitude + ' ' +
// 'Lon: ' + position.coords.latitude);
clat = position.coords.latitude;//40.353;//40.714623; //37.4419444;//40.353;//
clng = position.coords.longitude;//-74.673;//-74.006605;//-122.1419444;//-74.673;//
var myLatlng = new google.maps.LatLng(38,-97);
var myOptions = {
zoom: 3,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
mymap = new google.maps.Map(document.getElementById("map"), myOptions);
console.log('values to map current location' + 'lat: ' + clat + ' lng: ' + clng);
}
}
// Function for adding a marker to the page.
function addMarker(location, message) {
marker = new google.maps.Marker({
position: location,
map: mymap,
animation: google.maps.Animation.DROP
});
addInfoWindow(marker, message)
}
// function to add info window for markers
function addInfoWindow(marker, message) {
var cinfoWindow = new google.maps.InfoWindow();
var chtml = message;
google.maps.event.addListener(marker, 'click', function() {
cinfoWindow.setContent(chtml);
cinfoWindow.open(mymap, marker);
});
}
// function to add current location marker
function CurrentLocation() {
Marker1=new google.maps.LatLng(clat, clng); addMarker(Marker1, "Current Location");
}