0

How can I calculate the sunrise and sunset in the area that the user is visiting a site in with javascript / jquery ?

I tried looking at this question, but didn't get much help from the answers.

I just want to be able to print sunrise: sunrise time is here and sunset: sunset time here.

Community
  • 1
  • 1
Irfan Mir
  • 2,107
  • 8
  • 27
  • 33

2 Answers2

1

A quick solution is to use XMLHTTPRequest to a script that returns the result from PHP's date_sunrise/date_sunset methods:

http://php.net/manual/en/function.date-sunrise.php

Otherwise, you'll have to maintain a database of the required information and reproduce that algorithm. However, this looks like it might do it out of the box:

http://www.github.com/mourner/suncalc

Giuseppe
  • 73
  • 1
  • 10
  • Hmmm interesting. How can I get the longitude and latitude of the user's machine then to pass to those functions? – Irfan Mir May 05 '13 at 01:16
0

Another solution is to query an existing service. Here is a similar question: link

Community
  • 1
  • 1