-
Notifications
You must be signed in to change notification settings - Fork 0
/
updateImage.js
81 lines (74 loc) · 1.88 KB
/
updateImage.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
var id;
function getImage()
{
if(navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(getData, showError);
}
}
function getData(position)
{
$.ajax({
url: "QueryDatabase.php",
type: "get",
data:
{
latitude: position.coords.latitude,
longitude: position.coords.longitude
},
success: function(response, textStatus, jqXHR)
{
MakePicture(jqXHR);
console.log(response);
}
});
}
function updateImageData(photoID)
{
if (navigator.geolocation)
{
id = photoID;
navigator.geolocation.getCurrentPosition(pushData,showError);
}
}
function pushData(position)
{
$.ajax({
url: "addTimestamp.php",
type: "post",
data: {guid: id,
latitude: position.coords.latitude,
longitude: position.coords.longitude},
// callback handler that will be called on success
success: function(response, textStatus, jqXHR){
// log a message to the console
console.log("Hooray, it worked!");
},
// callback handler that will be called on error
error: function(jqXHR, textStatus, errorThrown){
// log the error to the console
console.log(
"The following error occured: "+
textStatus, errorThrown
);
}
});
}
function showError(error)
{
switch(error.code)
{
case error.PERMISSION_DENIED:
alert("User denied the request for Geolocation. To allow geolocation on the Iphone, go to Settings > General > Reset location and Privacy");
break;
case error.POSITION_UNAVAILABLE:
alert("Location information is unavailable.");
break;
case error.TIMEOUT:
alert("The request to get user location timed out.");
break;
case error.UNKNOWN_ERROR:
alert("An unknown error occurred.");
break;
}
}