/
app.js
61 lines (49 loc) · 1.57 KB
/
app.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
var UI = require('ui');
var ajax = require('ajax');
var loading = new UI.Card({
title: 'Loading...',
subtitle: 'Locate Me',
body: 'We help you find you'
});
loading.show();
var locationOptions = {
enableHighAccuracy: true,
maximumAge: 10000,
timeout: 10000
};
function locationSuccess(pos) {
var lat;
var lang;
var location;
console.log('Got location: lat= ' + pos.coords.latitude + ' lon= ' + pos.coords.longitude);
lat = pos.coords.latitude;
lang = pos.coords.longitude;
ajax({
url: 'https://maps.googleapis.com/maps/api/geocode/json?latlng=' + lat + ',' + lang + '&key=AIzaSyC-8qQw6BCorqyWEkV5psNf9q2SvrpIf4Y',
type: 'json'
},
function(data, status, request) {
console.log(JSON.stringify(data));
console.log('Your Location Is: ' + data.results[0].formatted_address);
location = data.results[0].formatted_address;
var main = new UI.Card({
title: 'Locate Me',
body: 'You are at: ' + location
});
main.show();
},
function(error, status, request) {
console.log('The ajax request failed: ' + error);
}
);
}
function locationError(err) {
console.log('location error (' + err.code + '): ' + err.message);
var errorpage = new UI.Card({
title: 'Whoops!',
body: 'Looks like something went wrong! Chances are you have your GPS turned off. Try leaving this app, turning it back on, and come back'
});
errorpage.show();
}
// Make an asynchronous request
navigator.geolocation.getCurrentPosition(locationSuccess, locationError, locationOptions);