Android Question Time difference based on latitude and longitude

khwarizmi

Active Member
Licensed User
Longtime User
Hi all

How can I use the GNSS library to obtain the time in another country, taking into account the time in my country based on latitude and longitude?
 

udg

Expert
Licensed User
Longtime User
knowing that my application relates to exams for students in different countries and they must sit for the electronic exam at the same time.
I would have suggested to investigate whether a BLE Beacon (or similar) could be a viable solution.
I mean, each classroom has its own beacon with RTC feature.
Students enter the room, scan for the beacon and your app knows exactly where they are and what time is it
 
Upvote 0

khwarizmi

Active Member
Licensed User
Longtime User
It might be useful to bear in mind that the ticks Long value returned by DateTime.Now is the same everywhere around the world at the same time.



I'm not sure how your process could electronically enforce and audit the "exam at the same time" requirement, without an internet connection.
DateTime.Now depends on the timing of the device, and the student may manipulate the timing.
In my system, students download the exam file in advance, and are only allowed to enter at the time specified for the start of the exam, and there is a password that they receive at the time of the exam.
At the end of the exam, the application sends the students’ answers. If an Internet failure occurs at the moment of sending, the application keeps a copy of the answers to be sent later.
As much as possible, I tried to limit Internet tasks to specific times.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Yes, beacons. AFAIK, there are beacons sporting an RTC clock on board.
My idea is that your app let the user select the place where he/she is to attend the exam. The beacon is used to validate the place and read local time. If place and time are correct the exam is allowed.
Basically they will need to download and install your app when and where there is good connection.
Then beacons will be used as traffic lights to allow or deny partecipation to a given exam session.
The app collects data.
When Internet link is available, app transmit data to your server.

So, beacons are used to confirm that a candidate is in the right place at the right time.
 
Upvote 0

QSerg

Member
Time zone map is VERY strange and irregular. Look for example at Singapore. Using longitude and latitude with some "magic" formula will render almost useless result.
 
Upvote 0

mjcoon

Well-Known Member
Licensed User
@khwarizmi The only thing you can calculate from Lat/Long is Local Mean Time (LMT) based on Longitude offset from UTC..... That is midday when the sun reaches it's zenith at any point on the earth. LMT is only useful for calculating Sunrise/Sunset and other nautical/celestial events.

Some countries have adopted local time offsets from GMT in one hour steps, some X hours and 30 mins, some X hours and 15 minutes. Many countries adopt Daylight Savings Time in winter, but the dates vary between countries. Some countries do not change the clocks at all. China, for instance, spans 60°+ of longitude which gives a LMT span of 4 hours, yet observes GMT+8 across the whole country all year round. (1 hour LMT change = 15° of longitude)

There is probably a database somewhere where you can query a Lat/Long position and find out what country you are in. You could compile a database of countries with their GMT offsets and DST changing dates but as countries vary their DST dates all the time, keeping the database maintained would be a nightmare!

I take your point about internet availability but to me the Google Time Zone API seems like the only workable solution.

Time Zone API
Yes, it's quite political; the times as actually used by residents rather than solar time. BTW Surely Daylight Savings Time is used in summer, not winter (in UK, for instance). That's because there is then more daylight than a normal working day, so there is some scope for shuffling the clocks around to get a better fit.
 
Upvote 0

rabbitBUSH

Well-Known Member
Licensed User
Hi all

How can I use the GNSS library to obtain the time in another country, taking into account the time in my country based on latitude and longitude?
Timeanddate.com has these and an expensive API set. One of their online calculators does what you describe. They say this as well, see the quote below : (maybe one of these two places will share time calculator methods publicly. Navy people must need to do this. The observatory at Greenwich as well. Ask them.)

For astronomical calculations, we use algorithms developed by the US Naval Observatory and NASA's Jet Propulsion Laboratory.
 
Upvote 0
Top