Shop OBEX P1 Docs P2 Docs Learn Events
Time Zones via GPS anyone know? — Parallax Forums

Time Zones via GPS anyone know?

mctriviamctrivia Posts: 3,772
edited 2013-02-03 08:24 in General Discussion
I am trying to figure out how to find the current time zone when I know the longitude and latitude but can't find any kind of map or code snipet to do this. anyone know how?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Lots of propeller based products in stock at affordable prices.

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2010-05-14 12:57
    Time zones correspond only roughly·to the meridians.· Zones stray from meridians in almost every, if not every,·instance.· If you can find a position and have an extensive database to·reference then you could determine your time zone.

    http://24timezones.com/

    Post Edit -- The whole of Red China is on Peking time.

    Post Edited (PJ Allen) : 5/14/2010 1:02:12 PM GMT
  • mctriviamctrivia Posts: 3,772
    edited 2010-05-14 13:10
    Yes I know. I am trying to get that extensive database. but though I can find pictures of where the time zone boarders are. I can't seem to find a polygon map that I can compare my point to.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Lots of propeller based products in stock at affordable prices.
  • edited 2010-05-14 13:11
    I entered this into google as:

    how do you find the time zone for a gps?

    And the first link on the list provided some clues.

    http://www.vbrad.com/article.aspx?id=35
  • mctriviamctrivia Posts: 3,772
    edited 2010-05-14 13:17
    that sounds like what I want. But I do not see an option to download the code and the code shown does not show how to do it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Lots of propeller based products in stock at affordable prices.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2010-05-14 13:34
    That'll be an extensive database even with a coarse granularity.

    0 N, 0E = __; 0N, 1E = __;...
  • mctriviamctrivia Posts: 3,772
    edited 2010-05-14 13:44
    It would have to be in the form of regions not pixels.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Lots of propeller based products in stock at affordable prices.
  • edited 2010-05-14 14:27
    I think the key to solving this is knowing how you dould do this in your head by using a paper map, pencil, paper, calculator, etc before you take it to a computer or microcontroller.

    "Standard time zones can be defined by geometrically subdividing the Earth's spheroid into 24 lunes (wedge-shaped sections), bordered by meridians each 15° of longitude apart. The local time in neighboring zones would differ by one hour. However, political boundaries, geographical practicalities, and convenience of inhabitants can result in irregularly-shaped zones. Moreover, in a few regions, half-hour or quarter-hour differences are in effect."

    http://en.wikipedia.org/wiki/Time_zone
  • mctriviamctrivia Posts: 3,772
    edited 2010-05-14 14:41
    in canada if I was looking at a map i would determine which province the location was in first as most time zones align themselves with provincial boarders.

    With a calculator/computer it is relitively easy to compute if a location is within a triangular region. If we made a map of the world out of triangles I would first search for all triangles anywear near my location then compute if I am within any of them


    for example the following code generates a search query of my picture database to see if there are any pictures close to the designated location. It is quick and dirty but it reduces the large database down to a small number of results which I can then do more accurate calculations on.
    function SQLclosepictures($lat,$long,$d) {
      $latmax = $lat+($d/111.222222);
      $latmin = $lat-($d/111.222222);
      if ((abs($latmax)>90) or (abs($latmin)>90)) {
        return 'SELECT * FROM `pics` WHERE `latitude`>' . $latmin . ' AND `latitude`<' . $latmax;
      } else {
        $l=abs($long);
        if ($l<5) {
          $ls = $d/111.2;
        } elseif ($l<10) {
          $ls = $d/110.8;
        } elseif ($l<15) {
          $ls = $d/109.5;
        } elseif ($l<20) {
          $ls = $d/107.4;
        } elseif ($l<25) {
          $ls = $d/104.5;
        } elseif ($l<30) {
          $ls = $d/100.8;
        } elseif ($l<35) {
          $ls = $d/96.3;
        } elseif ($l<40) {
          $ls = $d/91.09;
        } elseif ($l<45) {
          $ls = $d/85.18;
        } elseif ($l<50) {
          $ls = $d/78.63;
        } elseif ($l<55) {
          $ls = $d/71.47;
        } elseif ($l<60) {
          $ls = $d/63.78;
        } elseif ($l<65) {
          $ls = $d/55.6;
        } elseif ($l<70) {
          $ls = $d/46.99;
        } elseif ($l<75) {
          $ls = $d/38.03;
        } elseif ($l<80) {
          $ls = $d/28.78;
        } else {
          $ls = $d/19.31;
        }
        $longmax = $long+$ls;
        $longmin = $long-$ls;
        return 'SELECT * FROM `pics` WHERE `latitude`>' . $latmin . ' AND `latitude`<' . $latmax . ' AND `longitude`>' . $longmin . ' AND `longitude`<' . $longmax;
      }
    }
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Lots of propeller based products in stock at affordable prices.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-05-14 17:06
    geonames.org probably has the info you need in their downloadable database, but it doesn't look like it's in a very convenient form for what you're trying to do. Their forum (forum.geonames.org/gforum/forums/list.page) may have people more knowledgeable about the subject, who could help you more than we can.

    -Phil
  • mctriviamctrivia Posts: 3,772
    edited 2010-05-14 18:09
    Thanks. It does not look like they store time zone info but I have asked anyways to see. Since my application is for a web server I can always have it poll another web site to do the conversion for me but it would be nice to find the information so I can also right an object for the propeller(though I am sure an SD card would be needed)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Lots of propeller based products in stock at affordable prices.
  • mctriviamctrivia Posts: 3,772
    edited 2010-05-14 18:21
    found an internet solution

    http://worldtimeengine.com/dotime/n49.837405_w99.934820/

    where n49.837405_w99.934820 is the location. should not be to hard to parse and gives all needed info.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Lots of propeller based products in stock at affordable prices.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-05-14 20:41
    'Didn't realize your app was net-connected. Here's a short tutorial on doing it in Ruby with geonames.org: chrischandler.name/ruby/converting-latitude-and-longitude-to-timezones/.

    -Phil
  • mctriviamctrivia Posts: 3,772
    edited 2010-05-14 20:47
    well parsing the xml returned from http://ws.geonames.org/timezone?lat=49.837405&lng=-99.934820 will be a lot easier then the site i mentioned. the site is coded in php so I can't use there function but it will be easy to write my own based off it. thanks.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Lots of propeller based products in stock at affordable prices.
  • Cluso99Cluso99 Posts: 18,069
    edited 2010-05-16 10:18
    Next you will have to consider Daylight Saving and the fact that it keeps varying, well at least in Australia it does!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Links to other interesting threads:

    · Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
    · Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
    · Prop Tools under Development or Completed (Index)
    · Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
    · Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
    My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz
  • CannibalRoboticsCannibalRobotics Posts: 535
    edited 2013-02-01 11:38
    I don't think zip codes cross time zones as they are driven by the same political boarders. Here is a zip code database with all of the time zones.
    http://www.zipinfo.com/products/z5p/z5p.htm I'll bet there is also a listing of lat/lon for establishing zip by GPS.
  • Prophead100Prophead100 Posts: 192
    edited 2013-02-01 18:19
    Take a look at the "Solar" object on the OBEX. The method "Merdian_Calc" will determine the closest meridian then its a simple divide by 15 degree to get the hour offset for the local time zone. The code will also show you some examples of floating point math.
  • Mark_TMark_T Posts: 1,981
    edited 2013-02-03 05:37
    Just a random thought - how far offshore do timezones extend? In mid-ocean clearly one can default to the 15 degree segments, but near land presumably the
    local coastline's timezone would apply? This page seems to answer these questions and mentions the tricky problem of working out maps of territorial v. internation waters:
    http://efele.net/maps/tz/world/
  • Heater.Heater. Posts: 21,230
    edited 2013-02-03 06:38
    mctrivia,

    That timezone service is very nice, they have lots of other good stuff there as well. The response will be even easier to parse if you ask for JSON format.

    Request:

    http://ws.geonames.org/timezoneJSON?lat=49.837405&lng=-99.934820

    Respnse:

    {"time":"2013-02-03 08:31",
    "countryName":"Canada",
    "sunset":"2013-02-03 17:37",
    "rawOffset":-6,
    "dstOffset":-5,
    "countryCode":"CA",
    "gmtOffset":-6,
    "lng":-99 .93482,
    "sunrise":"2013-02-03 08:10",
    "timezoneId":"America/Winnipeg",
    "lat":49.837405
    }
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2013-02-03 08:24
    I happen to reside in the world's largest time zone since China prefers to have one and only one for their entire nation and I coincidently align with the zone it is supposed to be.

    Over 1 billion 344 million people have just one time zone! Odd, very odd.

    But it seems no one has mentioned the other bugaboo, Daylight Savings Time. And of course, there is double daylight savings, war time, and other adjustments that overlay time zones.

    I presume the goal is to determine what time the person at a given location thinks it should be.

    Please note the offset in the above listing -- raw offsett, dst offset, and gmt offset.
Sign In or Register to comment.