- GPS: Inline

- GMaps: Inline
- get_coords() gibt jetzt auch die Adresse zurück
This commit is contained in:
Andreas Bielawski
2016-08-06 23:11:53 +02:00
parent 8a1b16429d
commit 40dd62c477
3 changed files with 58 additions and 30 deletions

View File

@ -363,24 +363,22 @@ end
-- Gets coordinates for a location. Used by gMaps.lua, time.lua, weather.lua.
function utilities.get_coords(input, config)
local url = 'https://maps.googleapis.com/maps/api/geocode/json?address='..URL.escape(input)..'&language=de'
local jstr, res = https.request(url)
if res ~= 200 then
return config.errors.connection
end
local url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' .. URL.escape(input)
local jstr, res = https.request(url)
if res ~= 200 then
return config.errors.connection
end
local jdat = json.decode(jstr)
if jdat.status == 'ZERO_RESULTS' then
return config.errors.results
end
return {
lat = jdat.results[1].geometry.location.lat,
lon = jdat.results[1].geometry.location.lng
}
local jdat = json.decode(jstr)
if jdat.status == 'ZERO_RESULTS' then
return config.errors.results
end
return {
lat = jdat.results[1].geometry.location.lat,
lon = jdat.results[1].geometry.location.lng,
addr = jdat.results[1].formatted_address
}
end
-- Get the number of values in a key/value table.