iPad Sun Calculator with Google Maps Support
I am a DIY learner and don‘t have a professional coding education. So I apologize upfront for not having structured my code as a professional would do.
The reason I post my project is to show what you can achieve as a non-professional by just examining the Pythonista examples program folders in Pythonista App, researching omz forum and stackoverflow.
The application I wrote calculates the Sun path coordinates including sunrise, noon and sunset data (direction and height in degrees) for a given day for any place on earth. This works completely offline including timezone deviation.
In addition to that, moon data is fetched from a server in Norway that offers a free moon data API. Based on that data I calculate moon phase, illumination and dates for coming new moon and full moon on my own.
A satellite picture is being taken from the given location and also a world map overview where you can see your selected spot.
The app provides a possibility to generate ODT and PDF report files (examples to be found in the linked zip file). You need a free Cloudmersive API key for PDF generation though. For ODT you need odfpy module (see installation manual which is also included) and there is also a free Open Office Distribution called AO Office in the Apple AppStore.
You can create, edit and delete new locations and please note that you can also change the satellite picture map size in the report settings menu for visualizing bigger geological structures. There is also an options switch in the report settings menu that includes moon data into the ODT/PDF report instead of the satellite picture.
There is also a Google Maps webview integrated for finding new locations to copying in your clipboard and processing from there. You need to zoom in and long press a location first, then press share button and close the app to properly adapt a location from Google maps web app. The Google Maps web app provides more clipboard information than Apple Maps so I used that one. The world map picture is fetched from Apple Maps though.
I know you can not only integrate Google Maps but also draw directly draw paths and spots into the live application that runs as a sub view in your app. I don‘t know yet how to do this however.
I hope you don’t face installation problems and that some of you bite your way through the installation process and give it a try.
Btw. the app is iPad only and refuses to work on iPhones (Maybe I do an iPhone version lateron).
[Edit: Dropbox archive link removed and replaced with GitHub link]
Here are some pictures:
cvp last edited by
@Bambla Nice job
Thank you very much. Btw., this little project could not have been finished without your omz forum answers in parts reaching years back, I should really mention you in the credits. 😅
For the others:
The app is fully offline operational, try flight mode. Online functions are disabled then, but core functions work.
You can also try „crazy input“, I.e. dates in the far future or past and then try „Seasons and DST switchtime“ in the output menu.
Most input should be intercepted, I really tried to react on user behavior that is hectic and unfocused so the app does not quit or show errors confusing the user.
Also try locations in the polar region in summer or winter, the app tells you when the sun does not rise or stays up all day.
Or try locations in the Southern Hemisphere, you see that the sun has its daily peak in the north, not in the south. If you choose a location close to the equator, the daily sun peak at noon might switch from north to south depending on the season due to shifted axis angle of 23,5 deg. Towards the sun.
You also see that in the equator region at noon, the sun „moves“ at high speed bc. there the earth rotates faster than towards the poles. When I calculate the middle of the day and highest sun peak, my resolution is in minutes. Within a minute, the sun can move very far in this region. That’s why you sometimes do not see the noon peak at 180, resp. 360 degrees sometimes.
Also, close to the equator it can happen that the sun is in autumn higher than in summer at solstice. That’s due to the shifted earth axis which lets the sun shine from higher above at some positions.
I did not invent all that astronomy math I just adapted it. And I am quite amazed what science is able to find out with pen, paper and looking at the stars.
I should really mention you in the credits
Don't do that, almost my posts are based on informations kindly given by a lot of guys here.
This app and its forum, and its developer of course, are all marvelous.
ccc last edited by ccc
@ccc I have created a new github Account upfront but then decided to provide a Dropbox zip, because when directly adapting github content from an ipad or iPhone with Safari, there is no button to download the master as zip file as you can see it when accessing github from a pc. The ipad app seems useless, too. You also cannot download single files with ipad or iPhone and there is no button to copy a whole script to clipboard. I must switch to raw view and manually select, copy and paste which is a pain when copying big scripts.
That’s why I thought Dropbox zip is a better alternative to fetch Content from a mobile Apple device.
But I have seen that all of you use github so I will do the same. I can also imagine that you can maybe import github content with stash Shell. In that case, forget what I wrote above. 😅
I will provide a github archive today and post it here. The iPhone version of this program is also just ready and I will try to use your json instead of pyui trick for this one. The iPhone Version will also be on github.
ccc last edited by
must switch to raw view and manually select, copy and paste which is a pain when copying big scripts.
As soon you know the (permanent) url of the raw version, this little script downloads the .py
url = 'https://raw.githubusercontent.com/your_user/..../suncalc.py' data = requests.get(url).content with open('suncalc.py', mode='wb') as out_file: out_file.write(data)
Thus it is easy to write, for instance, a little tool in the share sheet to download any GitHub file from its raw page.
See also my
DownloadGithubRawFile.pyin https://github.com/cvpe/Pythonista-scripts. Check its readme and its usage of folder_picker
@cvp Thank you very much for these little helpers making life easier with Github.
@ccc The github repo for the ipad version of SunCalc has just been created.
Can you please check if you can access it the same way as everyone else does? It is the first time ever I create something with github myself, I was a myself a passive github downloader until now.
I will also create a separate iPhone release, but this will take some more days. I have to translate ui changes to English and I also want to use JSON instead of pyui successfully, so the user has less manual installation steps.
Thank you for giving a short feedback if you could properly access and import all files.
Can you please check if you can access it the same way as everyone else does
The iPhone version is ready and uploaded to a separate github repository:
More compact ui
Weekeday abbreviations in English now (I forgot to translate
No more manual renaming of pyui and ttf required for local installation - it works with json and txt suffix now
I used ccc‘s optimized iPad code as a starting point for the iPhone version - still I had to put the „import arrow“ Statement at the end of the import block due to overwrite problems (ccc put it at a place where it fits better into the readability of the Code)
I still have too much cyclomatic complexity and after I re-placed the „import arrow“ Statement github sent me a message that lint tests failed. The Script works fine though, I still must learn what clean code is about.
Please see below in the Screenshots the way to copy new locations to clipboard from Google Maps to process the clipboard data in the app for calculations
wowase6344 last edited by
This post is deleted!
For everyone who has already downloaded the App from Github, please go to
for iPad and
and import the current file suncalc.py from there to your local Pythonista app directory.
When you use „My Location“ and „Current date“ the app did not recognize switch to Standard time since Oct 31st 2021.
This should now be fixed on both iPhone and ipad.
Hello, I added an additional script to both archives
This program (works both on iPad and iPhone) shows instant sun data of your current location at the current time, no matter where in the world you are.
The program works offline, you only need GPS enabled. A correct timezone recognition is implemented, too.
This program was originally supposed to be a widget but Pythonista won‘t display it because it is too complex.
Instead, I released it as a regular Pythonista Script. I hope it is useful to some of you.
Please find my latest addition for the iPhone version: a sun compass that uses the iPhone magnetometer and GPS.
The compass is precise, but you might need to calibrate the compass by moving the iPhone in the shape of a horizontal „8“.
When using the compass, hold the iPhone horizontal and parallel to the ground and rotate without rolling or pitching your phone, otherwise the compass fails.
I don’t know the magic the iOS compass app from Apple does to keep the value stable even if you roll and pitch the phone around.
Thecompass is realtime-tracking the time, your heading and the sun position and the app stays permanently open, but the GPS coordinate are not updated permanently, I decided it to be CPU waste to do so.
Instead, you get a position refresh at each new launch.
The app recognizes your time zone and DST Status, also if the sun does not rise or set at all. It works all offline, only GPS is required.
I had also memory leak issues with ui.imageview and bytesio first and switched to using scene. The app ran much longer but Pythonista still crashed. I finally fixed the issue by placing a gc command at the end of my while loop.
I stopped measuring run time with active Display after 1 hour. Note that your battery is being sucked empty quicker when the app is running.
Roll and pitch values of your iPhone for optimal horizontal positioning of your compass.
The values in the upper right corner must be both < 0.009xx in order to show the same heading as the official Apple iPhone compass app, given there are no other disturbing influences on the magnetometer.
As I already said above, the official iPhone compass app is more robust and you don’t need to treat it like a raw egg to ensure precision, but I don’t know what Apple does to achieve this.
Legendupdate1 last edited by ccc
This post is deleted!
New version available on github:
For both iPhone and iPad version the installation process has been simplified by not needing to manually rename files to *.pyui anymore.
Further, the result output of a selected date and a selected location now additionaly shows a 2D graphic containing the location of the earth on its path around the sun and the relative position of the sun towards earth at the given location including latitude.
In the example below we see the latitude of a location in Australia on the southern hemisphere as a long horizontal line, showing the longest duration of day length at winter solistice on December 21st, which is on the southern hemisphere actually a summer solistice.
On the iPhone version, the sun compass apps are still included. These are not contained in the iPad version, though.
The new 2D graphics use generic dates, i.e. 21.3., 21.6, 23.9. and 21.12 for astronomic seasons, whereas in reality, these dates can differ slightly. Further, the earth path around the sun is depicted as a perfect circle instead of an ellipse and I assume a constant moving speed of the earth, which is not true, but as an approximiation and to get a general understanding, I consider the picture to be useful.
When the commented line near the end is uncommented, it becomes modal and works, but it becomes slow and stutters when scrolling. Any ideas as https://valódijogosítvány.com/ to why it slows down?