Irfan Mir
Irfan Mir

Reputation: 2175

Calculate sunrise and sunset in javascript for user's location when they visit site

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.

Upvotes: 0

Views: 2203

Answers (2)

user1546328
user1546328

Reputation:

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

Upvotes: 0

Giuseppe
Giuseppe

Reputation: 73

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

Upvotes: 1

Related Questions