algorithm for getting time zone from geo coordinates

前端 未结 4 1421
春和景丽
春和景丽 2021-01-02 03:15

I want to write app where user can point any place on map (not only cities) and get timezone in that place.

What data structure (app will not have Internet connectiv

4条回答
  •  执念已碎
    2021-01-02 03:40

    Given that time zones are based on political entities rather than simply a physical lat/lon computation, I would create a data structure that mapped polygons over lat/lon coordinates into political entities (country and province/state) and then have a separate structure that mapped political entities and current date into timezone offset.

    That way you not only avoid redundancy, but also:

    1. You can display DST reference information independently of a specific set of coordinates, and
    2. When some country changes the rules for when daylight saving time begins and ends, you have one place to make the update.

    However, given the highly irregular shape of some borders, you'll need a fairly large data structure for accuracy, depending on the resolution of your input and/or display.

提交回复
热议问题