# TimeZone from latitude/longtitude

**URL:** <https://discourse.julialang.org/t/timezone-from-latitude-longtitude/55129>\
**Category:** Geo\
**Tags:** time\
**Created:** [February 12, 2021, 9:51am UTC](https://discourse.julialang.org/t/timezone-from-latitude-longtitude/55129 "2021-02-12T09:51:28Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![lubo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lubo/32/18895_2.png) [@lubo](https://discourse.julialang.org/u/lubo)\
**Post date:** [February 12, 2021, 9:51am UTC](https://discourse.julialang.org/t/timezone-from-latitude-longtitude/55129/1 "2021-02-12T09:51:28Z")

</div>

Hi,  
maybe very silly question, but can not find solution so far.  
I have gps coordinates of the city, ie place in Stockholm/Sweden: [59.3725,18.0].  
I would like to get TimeZone for this place: ‘Europe/Stockholm’

In python, there is lib: [timezonefinder · PyPI](https://pypi.org/project/timezonefinder/)

Please, what is the best solution to get this in Julia

Thanks a lot for help  
Lubo

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [February 12, 2021, 10:21am UTC](https://discourse.julialang.org/t/timezone-from-latitude-longtitude/55129/2 "2021-02-12T10:21:12Z")

</div>

Perhaps:

```julia
julia> using TimeZones

julia> TimeZone("Europe/Stockholm")
Europe/Stockholm (UTC+1/UTC+2)

```

(Assuming you know the “Europe/Stockholm”… I don’t know how you get the country from the Latitude/Longitude though…)

---

<div class="post-metadata">

**Author:** ![lubo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lubo/32/18895_2.png) [@lubo](https://discourse.julialang.org/u/lubo)\
**Post date:** [February 12, 2021, 10:38am UTC](https://discourse.julialang.org/t/timezone-from-latitude-longtitude/55129/3 "2021-02-12T10:38:21Z")

</div>

Hi, thanks for the reply, but no, the point is that I do not know that these point belongs to Europe/Stockholm zone.

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [February 12, 2021, 10:49am UTC](https://discourse.julialang.org/t/timezone-from-latitude-longtitude/55129/4 "2021-02-12T10:49:07Z")

</div>

> [@lubo](#):
>
> I would like to get TimeZone for this place: ‘Europe/Stockholm’

Yes, I did wonder if you really meant "I would like to get TimeZone for this place: `[59.3725,18.0]`. 😄You probably could use the Google Maps API or OpenStreetMap.

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [February 12, 2021, 12:02pm UTC](https://discourse.julialang.org/t/timezone-from-latitude-longtitude/55129/5 "2021-02-12T12:02:32Z")

</div>

I don’t know this exists in Julia. Then, in this case (or for other obscure Python packages) I would use PyCall.jl, and use that Python package.

```julia
julia> using PyCall

julia> py"""
       from timezonefinder import TimezoneFinder

       tf = TimezoneFinder()
       latitude, longitude = 52.5061, 13.358
       """
/home/pharaldsson_sym/.local/lib/python3.6/site-packages/numba/core/errors.py:149: UserWarning: Insufficiently recent colorama version found. Numba requires colorama >= 0.3.9
  warnings.warn(msg)

julia> my_timezone = py"tf.timezone_at(lng=longitude, lat=latitude)"
"Europe/Berlin"

```

You would want to change it a bit more, e.g. to interpolate Julia variables in (and import differently, see PyCall docs, maybe use Conda):

```julia
julia> my_timezone = py"tf.timezone_at(lng=$longitude, lat=$latitude)"

```

and get rid of the warning, but that seems like a problem you would also need to figure out in Python anyway.

Ironically, the example from the Python docs didn’t work for me in Python3 nor 2, while it did work in Julia.

I first did (you would also need in Python):

```julia
$ pip3 install timezonefinder
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: timezonefinder in ./.local/lib/python3.6/site-packages (5.2.0)
Requirement already satisfied: numpy>=1.16 in ./.local/lib/python3.6/site-packages (from timezonefinder) (1.18.1)

```

I finally tried:

```julia
$ pip3 install timezonefinder[numba]

```

and it does something differently, and Julia keeps working but not Python, neither with pip (for Julia pip3 may be needed). I thought [numba] meant option as in use timezonefindernumba, but that’s not it so I learned something new.

---

<div class="post-metadata">

**Author:** ![fabiangans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fabiangans/32/2624_2.png) [@fabiangans](https://discourse.julialang.org/u/fabiangans)\
**Post date:** [February 12, 2021, 1:35pm UTC](https://discourse.julialang.org/t/timezone-from-latitude-longtitude/55129/6 "2021-02-12T13:35:24Z")

</div>

If you wanted to make a pure-Julia solution it looks like the python package uses the shapefiles provided by this project:

[https://github.com/evansiroky/timezone-boundary-builder](https://github.com/evansiroky/timezone-boundary-builder)

If one combines this with a point-in-polygon algorithm e.g. from here:

[https://github.com/JuliaGeometry/PolygonOps.jl](https://github.com/JuliaGeometry/PolygonOps.jl)

this should be all you need for a Julia TimeZoneFinder.jl

---

<div class="post-metadata">

**Author:** ![lubo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lubo/32/18895_2.png) [@lubo](https://discourse.julialang.org/u/lubo)\
**Post date:** [February 13, 2021, 9:57am UTC](https://discourse.julialang.org/t/timezone-from-latitude-longtitude/55129/7 "2021-02-13T09:57:29Z")

</div>

Thank you all for answers, for the reference, there is also web API: [API Access for Developers - TimeZoneDB](https://timezonedb.com/api)

---

<div class="post-metadata">

**Author:** ![tpgillam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tpgillam/32/23052_2.png) [@tpgillam](https://discourse.julialang.org/u/tpgillam)\
**Post date:** [August 22, 2022, 3:50pm UTC](https://discourse.julialang.org/t/timezone-from-latitude-longtitude/55129/8 "2022-08-22T15:50:44Z")

</div>

I was trying to do this too, and still couldn’t find a native Julia solution, so I had a go at making one: [https://github.com/tpgillam/TimeZoneFinder.jl](https://github.com/tpgillam/TimeZoneFinder.jl) (the implementation is pretty trivial, and primarily delgates to Meshes.jl for actual work)

The initial version will be available on the General registry after the 3 day cliff — after that there’s some performance optimisation I’ll hopefully have a chance to work on.

Please file issues liberally! 🙂
