How to calculate the sunrise and sunset in javascr

2019-05-26 07:54发布

i am using appcelerator titanium to develop an IOS app and i want to let my app send local notification to the users in sunrise and sunset

a good tool to solve this is Yahoo weather using YQL ; however, yahoo weather is for non-commercial use only!!

i am trying to find a javascript library to calculate the sunrise/set + a database of the world's countries and cities with the latitude and longtude

have anyone ever needed the same?

Any idea.

4条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-05-26 08:35

Use NOAA's javascript routines for the solar position: here

They include a short list of cities with latitude and longitude. I think you can also get that from iOS, but here's another answer on getting it from city, state, etc.

查看更多
Emotional °昔
3楼-- · 2019-05-26 08:52

This algorithm looks pretty wicked to solve exactly what you're looking to do.

查看更多
祖国的老花朵
4楼-- · 2019-05-26 08:55

I wrote a Google Gadget (javascript) for sunrise and sunset calculation based on lat/lon located here.

It was written from algorithms in Duffett-Smith 'Practical Astronomy with your Calculator'.

查看更多
太酷不给撩
5楼-- · 2019-05-26 08:55

With iOS (and likely other location enabled devices) you can get the users current location if they allow it. You can then use the local time and timezone offset to calculate the sunrise and sunset from their latitude and longitude.

It won't take into account local geographic effects on the horizon (e.g. if they are in a valley the sun will rise or set earlier than if they are on a hill) but it should be close enough. Use Google, I'm sure you'll find it - ah, I see Demian has done it for you.

查看更多
登录 后发表回答