-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetGeo.js
More file actions
40 lines (31 loc) · 1.33 KB
/
getGeo.js
File metadata and controls
40 lines (31 loc) · 1.33 KB
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
/*
getGeo using location IQ
getGeoHERE using here maps
## here maps is less accurate but use it for sake of project
//all requests are simple ajax requests
ASYNC so place callback function which will receive a parsed JSON object
E.G getGeoHERE('-26.150353,27.932031' ,function(obj){ console.log(obj) } )
getGeo(-26.150353, 27.932031, function(obj){ console.log(obj) } )
*/
function getGeo(lat, lon , callback){
var statusR = new XMLHttpRequest();
statusR.onreadystatechange = function() {
console.log(statusR.response)
if (statusR.readyState == 4 && statusR.responseText != 'error') {
callback(JSON.parse(statusR.response))
}
}
statusR.open("GET", 'https://us1.locationiq.com/v1/reverse.php?key=cbe1019cc2965e&lat='+lat+'&lon='+lon+'&format=json', true);
statusR.send(null);
}
function getGeoHERE(latlon, callback){
var statusR = new XMLHttpRequest();
statusR.onreadystatechange = function() {
console.log(statusR.response)
if (statusR.readyState == 4 && statusR.responseText != 'error') {
callback(JSON.parse(statusR.response))
}
}
statusR.open("GET", 'https://reverse.geocoder.api.here.com/6.2/reversegeocode.json?prox='+latlon+'&mode=retrieveAddresses&maxresults=1&gen=9&app_id=B4reavFnn0uYvunnrT5F&app_code=nsgciwl5LqSQPG0AbV0meg', true);
statusR.send(null);
}