-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
100 lines (94 loc) · 3.61 KB
/
main.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
// default latitude and longitude values
var latitude = 50.371087;
var longitude = -4.144646;
$( document ).on( "pageinit", "#main", function() {
$.getJSON("markers.json", function(jsonRec) {
var str = "";
$.each(jsonRec, function(key, val) {
//str += "<li class='ui-screen-hidden'><a href='./search.html'>"+val.Instructor+"</a></li>";
str += "<li class='ui-screen-hidden'><a onclick='showSearchLocation("+val.Latitude+","+val.Longitude+")'>"+val.Instructor+": "+val.DiveCountry+"</a></li>";
});
$("#searchList").html(str);
$("#searchList").listview("refresh");
$("#searchList").trigger( "updatelayout");
});
});
function getCurrentLocation() {
if ( navigator.geolocation ) {
function success(pos) {
// Location found, show map with these coordinates
latitude = pos.coords.latitude;
longitude = pos.coords.longitude;
console.log("navigator.geolocation success - coordinates: " + latitude + ", " + longitude);
$.mobile.changePage("map.html")
}
function fail(error) {
var errors = {
1: 'Permission denied - You may need to change your location settings to allow',
2: 'Position unavailable',
3: 'Request timeout'
};
console.log("Error: " + errors[error.code]);
$("#errorpopuptext").html(errors[error.code]);
$("#locationerrorpopup").popup("open")
}
// Find the users current position. Cache the location for 5 minutes, timeout after 6 seconds
navigator.geolocation.getCurrentPosition(success, fail, {maximumAge: 500000, enableHighAccuracy:false, timeout: 6000});
} else {
console.log("navigator.geolocation error");
$("#errorpopuptext").html("Your device does not appear to have geolocation support");
$("#locationerrorpopup").popup("open")
}
}
function showSearchLocation(searchLat, searchLong) {
latitude = searchLat;
longitude = searchLong;
console.log("nshowSearchLocation - coordinates: " + latitude + ", " + longitude);
$.mobile.changePage("map.html")
}
/*
* Google Maps documentation: http://code.google.com/apis/maps/documentation/javascript/basics.html
* Geolocation documentation: http://dev.w3.org/geo/api/spec-source.html
*/
$( document ).on( "pageshow", "#map-page", function() {
console.log("page loading");
console.log("latitude: " + latitude + ", longitude: " + longitude);
drawMap(new google.maps.LatLng(latitude, longitude));
function drawMap(currLatLng) {
var mapOptions = {
zoom: 7,
center: currLatLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
// read the data from file
$.getJSON("markers.json", function(jsonRec) {
var mapIcon = 'images/icon.png';
$.each(jsonRec, function(key, data) {
// Get the Latitude and Longitude from the file
var latLng = new google.maps.LatLng(data.Latitude, data.Longitude);
// Create a marker and put it on the map
var marker = new google.maps.Marker({
position: latLng,
title: data.Instructor + ", " + data.City,
icon: mapIcon
});
// Add an info window
var infoWindow = new google.maps.InfoWindow({
content:'<div class="info-window"><img src="images/' + data.Photo + '" width="50" height="50">'
+ '<b> ' + data.Instructor + '</b>'
+ '<p><i>' + data.Bio + '</i></p>'
+ '<p>Location: ' + data.City + ', ' + data.Country + '</p>'
+ '<p>Language/s: ' + data.Language + '</p>'
+ '<p>Specialities: ' + data.DiveSite + '</p>'
+ '<p>Countries: ' + data.DiveCountry + '</p>'
+ '</div>'
});
google.maps.event.addListener(marker, 'click', function() {
infoWindow.open(map,marker);
});
marker.setMap(map);
});
});
}
});