Technical Information about the Bearing to Yerushalayim Map

Vintage Map with CompassI have been asked a number of questions recently about the directional accuracy of the Bearing to Yerushalayim and Zmanim Map calculations. The rhumb line calculations are very straightforward, and I will not spend much time on them in this article. As a side note, for those interested in the subject, I would like to mention that Rabbi Gavriel Goetz recently published a very comprehensive pamphlet, Gevuras Moishe, on the subject, and it is well worth reading.

My original calculations and implementation of the great circle route (geodesic line) used simple spherical trigonometry to calculate the initial bearing (and distance) based on a sphere using an authalic mean radius of 6,371 km. These calculations were very similar to the method used in Rabbi Yehuda Herskowitz’s article in Yeshurun volume III page 586. This model of the earth is more than accurate enough for these calculations (you would need a very accurate “nose alignment” and the total lack of shuckling to even get within a degree of being correct). The Google Maps API, Yahoo Maps and Microsoft’s Live Maps, for simplicity’s sake, all use very similar calculations, as mentioned in the cfis blog quoting Morten Nielsen:

Google Maps / Virtual Earth / Yahoo Maps(?) all use a spherical datum based on WGS84. That is, it has the same center, orientation and scale as WGS84, but has no flattening. The radius of the sphere is the same as the semi-major axis of WGS84 (6378137 meters).

Using a sphere, all the above-mentioned mapping APIs use the spherical law of cosines formula for the calculations, which yields an identical result to the more complex haversine formula.

Curious how accurate these calculations really are, being based on a perfect sphere and not the oblate ellipsoid/spheroid that the earth actually is, I started looking into the subject a little more. The current standard reference ellipsoid model of the earth is the WGS84 model. The geodesist/mathematician Thaddeus Vincenty published the Vincenty formulae for this type of calculation, which are said to be accurate to about one-half millimeter, more than adequate for our calculation. Chris Veness implemented this formula in JavaScript and released it under the LGPL, making it very simple to use. I slightly modified his work to allow easier interaction with the Google Maps API. The implementation that I used when I finally published the map on December 30, 2007, uses the Vincenty formula with the WGS84 ellipsoid (the Vincenty formula can easily be used with different ellipsoid models). The table below compares the initial bearing and distance results of the different calculations for a Lakewood, NJ (latitude: 40.095965°, longitude: -74.22213°) to Har Habayis (latitude: 31.77805°, longitude: 35.235149°) example.

Calculation MethodInitial BearingDistance
6,371 km (authalic mean radius) sphere using spherical trigonometry53.86555°9224.67442 km
Google Maps API 6,378.137 km (WGS84 equatorial radius) sphere using spherical trigonometryN/A9235.00819 km
Vincenty formula using the WGS84 ellipsoid53.81786°9244.61686 km
rhumb line95.37152°9891.16074 km
Note: The table shows the original 2008 JavaScript results. Running the same calculations with version 3.1.0 of the KosherJava Zmanim API gives a Vincenty initial bearing of 53.81787° and distance of 9244.61720 km, and a rhumb line distance of 9891.16103 km. The distances differ by less than a meter, a result of small differences between the JavaScript and Java code.

Zmanim Via Instant Messaging Bot

Note: The ZmanimBot is no longer running, and both Google Talk and AIM have since been shut down. The links below point to archived copies where available.

As hinted at in my previous post, there is a new project underway that uses the Zmanim API in a way that I had never really imagined. Using the Smack API, Michael Kopinsky created the ZmanimBot that allows getting zmanim by instant messaging the ZmanimBot, an internet bot. It currently supports the Google Talk IM system, but support for other systems might follow. Please be aware that the system is under development and is not always up. Additional information can be found on the ZmanimBot page.

Update (ח׳ בניסן תשס״ח April 13, 2008): The ZmanimBot is now available via AIM.

Updated Zmanim Jar Released – Please Download the Latest

Note: This post is about an old release. The current version of the KosherJava Zmanim API is available on GitHub and from the Zmanim Download page.

In December, when developing the Zmanim/Bearing to Yerushalayim map (blog post), I noticed a problem with the code used to generate zmanim. The API returns a Java Date object. Usually only the time is of interest, and the date is ignored, but in some cases (when a time zone offset is specified without using an IANA time zone database name such as America/New_York, or when GMT is used for other locations and the local standard time is calculated as an offset of GMT), the date of the sunset returned was earlier than the sunrise date. This caused zmanim such as sof zman Shema to be incorrect for some locations, since the math was comparing sunrise to a sunset on the wrong date, causing some very odd behavior. Updated files that correct this issue were uploaded to the site on December 26. I was notified today by a developer using the jar that not all the download links were pointing to the updated versions, and this caused issues for his program (a post about his project will be posted in the near future). All the links have now been updated. Since the old code can sometimes generate incorrect zmanim, it is highly recommended that you replace your current jar with the latest version of zmanim.jar (or zmanim.zip).

Along with the fix mentioned above, a number of other small fixes were made. These include, among other minor issues, fixed, better and simplified XML output from the toString method, and better handling of expected error conditions that had previously caused errors in the generation of zmanim for areas within the Arctic Circle, such as Thule, Greenland. In case you are curious, someone did actually try this, and the error logs led me to find the issue. The IP address used for the request mapped back to Thule Air Base (renamed Pituffik Space Base in 2023).

Bearing to Yerushalayim and Zmanim Map

Update: The map has been rewritten several times since this post. The current version is the KosherJava Zmanim Map.

Did you ever find yourself unsure of the correct bearing (direction) to Yerushalayim (Jerusalem)? The new Zmanim/Bearing to Yerushalayim map will help you find it very easily. The map draws two lines from your location to Yerushalayim. The blue line uses the commonly used (לבוש Levush and others) rhumb line (a straight line on a Mercator projection map), while the green line shows the great circle route (Rabbi Aviad Sar Shalom Basilea הרב אביעד שר שלום באזילה in his אמונת חכמים Emunas Chachamim and others) on a map. While the great circle line does not appear straight on the map, on a globe the shortest (and straightest) line between two points follows the great circle route. Future posts will detail the technical aspects of the work involved. For additional information on the correct bearing for tefila, see Rabbi Yehuda Herskowitz’s article in Yeshurun volume III page 586 and Rabbi Gavriel Goetz’s comprehensive pamphlet Gevuras Moishe on the subject.

How to Use

Find your exact location on the map by dragging the marker to your exact location or by clicking anywhere on the map. You can also click on the search button and enter your location (such as “Lakewood, NJ” (the default) or “Vilnius, Lithuania”) or just enter a zip code (Canadian or British postal codes work as well) to zoom in on your location. Changing to satellite view and zooming in farther will make the job easier (assuming that you can identify your roof). Once the red marker is centered on your location, click the red marker to show your exact latitude, longitude and bearing to Yerushalayim in an info window. There are two additional tabs that show today’s zmanim. You can click on the “Link” button to refresh the page with the URL that contains coordinates to the currently displayed map with its zoom level so that it can be bookmarked or emailed.

I would like to thank Rabbi Yehuda Herskowitz for his excellent article and the additional information that he provided.

Known Issues

Google Maps API Bugs (All Fixed by Google)

  1. Zmanim data sometimes fails to show in Firefox. This seems to be a bug in the Google Maps API when dealing with synchronous AJAX calls.
  2. Locations close to 180° from Yerushalayim (Alaska is a good test case) sometimes show an incorrect rhumb line bearing (though the great circle route shows correctly). The information in the info window is correct. This is a known issue with the Google Maps API.
  3. Related to the above issue, sometimes the lines are drawn a “world away” and horizontal scrolling of the map is required to see the lines. Again, this is a known Google Maps issue.

To Do (Related to Zmanim)

  1. Support daylight saving time (supported by the time zone web service used, but not yet implemented in the map).
  2. Link to a yearly calendar.
  3. Elevation lookup (already available in the yearly calendar).
  4. Allow changing of the date.

Note that it is not clear that the Levush was of the opinion that the rhumb line should be used.

Zmanim Clock Applet Alpha Release

Java Logo Sepia

Note: Java applets are obsolete, and the applet is no longer available.

A while ago, Dr. Irv Bromberg mentioned to me that my Zmanim API was in use in the Astronomical Clock Applet created by Ali Adams. The applet was a modification to Antony Pranata’s clock applet that displayed Islamic prayer times. Apparently the Zmanim API was so flexible that without any modification it was able to be used for generating “zmanim” well beyond anything I had envisioned. At Dr. Bromberg’s suggestion, I modified the clock applet to display zmanim. Using the same Google Maps API used in the Calendar Generator, I created the Zmanim Clock page (no longer available). The clock on the Clock page is very configurable, and allows selection of the location, zmanim, etc. I contacted Antony Pranata, the original author of the clock, who allowed me to release it under the GPL. An easy-to-use downloadable version will be made available in the near future. For those who think that the clock is upside down, there are more than enough configuration options to tweak the clock to your heart’s content.