Skip to content

Instantly share code, notes, and snippets.

@Ismael-VC
Created November 28, 2016 21:04
Show Gist options
  • Save Ismael-VC/393c3240767d04ee9c23e134a23c8c57 to your computer and use it in GitHub Desktop.
Save Ismael-VC/393c3240767d04ee9c23e134a23c8c57 to your computer and use it in GitHub Desktop.
Reverse Geocoding in Julia.
C:\Users\Ismael
λ julia
_
_ _ _(_)_ | By greedy hackers for greedy hackers.
(_) | (_) (_) | Documentation: http://docs.julialang.org
_ _ _| |_ __ _ | Type "?help" for help.
| | | | | | |/ _' | |
| | |_| | | | (_| | | Version 0.5.0 (2016-09-19 18:14 UTC)
_/ |\__'_|_|_|\__'_| | Official http://julialang.org/ release
|__/ | x86_64-w64-mingw32
julia> using Requests: get, json
julia> @doc """
Return reverse geocoding data as `Dict`,
valid `api`s are symbols: `:google` and `:openstreetmap`
""" ->
function reverse_geocoding(latitude, longitude; api = :google)
APIs = Dict(
:google => "https://maps.googleapis.com/maps/api/geocode/json?latlng=$latitude,$longitude",
:openstreetmap => "http://nominatim.openstreetmap.org/reverse?format=json&lat=$latitude&lon=$longitude"
)
response = get(APIs[api])
return response.status == 200 ? json(response) : response
end
reverse_geocoding
julia> latitude, longitude = "19.19059131" , "-99.1398181755643"
("19.19059131","-99.1398181755643")
julia> reverse_geocoding(latitude, longitude)
Dict{String,Any} with 2 entries:
"status" => "OK"
"results" => Any[Dict{String,Any}(Pair{String,Any}("address_components",Any[Dict{String,Any}(Pair{String,Any}("short_name","88"),Pair{String,Any}("types",Any["street_nu…
julia> reverse_geocoding(latitude, longitude, api = :openstreetmap)
Dict{String,Any} with 9 entries:
"lat" => "19.1995444"
"address" => Dict{String,Any}(Pair{String,Any}("state","CDMX"),Pair{String,Any}("postcode","14500"),Pair{String,Any}("country_code","mx"),Pair{String,Any}("county"…
"place_id" => "76870331"
"display_name" => "Del Rastro, Topilejo, Tlalpan, CDMX, 14500, México"
"licence" => "Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright"
"osm_id" => "53011334"
"lon" => "-99.1400892"
"boundingbox" => Any["19.1985159","19.2032173","-99.1442195","-99.1363364"]
"osm_type" => "way"
julia>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment