diff options
| author | Gubolin <gubolin@fantasymail.de> | 2014-08-18 14:28:52 +0200 |
|---|---|---|
| committer | Gubolin <gubolin@fantasymail.de> | 2014-08-18 14:28:52 +0200 |
| commit | 667aa5a56564d07c05182eeae7bba7567710a844 (patch) | |
| tree | 1a4391ce15fd73eeea406ff6074c3f4583e4616b /threads.js | |
| parent | 624bcf4e3352971a77cf3e6a4266f1600f9da577 (diff) | |
| download | snap-667aa5a56564d07c05182eeae7bba7567710a844.tar.gz snap-667aa5a56564d07c05182eeae7bba7567710a844.zip | |
add geolocation blocklocation
Diffstat (limited to 'threads.js')
| -rw-r--r-- | threads.js | 61 |
1 files changed, 61 insertions, 0 deletions
@@ -2583,6 +2583,67 @@ Process.prototype.reportLanguage = function () { return 'en'; }; +Process.prototype.reportLocation = function (name) { + var myself = this; + + if (!myself.context.jsonpScript) { + if (!navigator.geolocation) { + myself.handleError({name: 'Location', + message: 'navigator.geolocation is not supported'}); + } + window.OSM_JSONP_Callback = function (data) { + myself.context.json = data; + window.OSM_JSONP_Callback = undefined; + }; + myself.context.jsonpScript = document.createElement('script'); + + navigator.geolocation.getCurrentPosition( + function (pos) { + var crd = pos.coords; + + myself.context.jsonpScript.src = + 'https://nominatim.openstreetmap.org/reverse' + + '?format=json&json_callback=OSM_JSONP_Callback' + + '&zoom=18&addressdetails=1' + + '&lat=' + + crd.latitude + + '&lon=' + + crd.longitude; + document.getElementsByTagName('HEAD')[0] + .appendChild(myself.context.jsonpScript); + }, + function (err) { + console.log(err); + myself.handleError({name: 'Location', message: err}); + }, + { enableHightAccuracy: true, timeout: 30000, maximumAge: 0} + ); + } else { + if (myself.context.json) { + switch (myself.inputOption(name)) { + case 'all': + return myself.context.json.display_name; + case 'state district': + return myself.context.json.address.state_district; + case 'house number': + return myself.context.json.address.house_number; + case 'licence': + return myself.context.json.licence; + case 'country': + case 'state': + case 'suburb': + case 'city': + case 'road': + return myself.context. + json.address[myself.inputOption(name)]; + } + } + } + + this.pushContext('doYield'); + this.pushContext(); +}; + // Process Dates and times in Snap // Map block options to built-in functions var dateMap = { |
