Bearing to Yerushalayim and Zmanim Map 3.0

Vintage Map with Compass

Update: The map was updated to version 3.5 in November 2012 (see Zmanim Map 3.5 adds Date and Algorithm Selection), and was rewritten from the ground up as Zmanim Map 4.0, now at ZmanimMap.com, in November 2026 (see Introducing ZmanimMap.com). Very little of the code described below remains.

The Bearing to Yerushalayim and Zmanim Map was recently updated to version 3.0. This new release adds a number of new features to the Zmanim Map version 2.0 update released in March 2010. The main change was updating the Google Maps API version from the deprecated v2 to v3. This change increases performance and adds much better support for mobile browsers. The upgrade also means that a Google Maps API key is no longer required. This makes it easy to drop it into any site without any configuration (contact me for details). Zmanim tab v3The technical notes on the original Technical Information about the Bearing to Yerushalayim Map post are still relevant, with very little having changed since the initial implementation.

The following is a partial list of the new features:

  • A number of additional zmanim in the More Zmanim tab, including tchilas and sof zman Kiddush Levana (if they occur on that day).
  • A link to download a 12-month zmanim calendar directly from the map (using the same spreadsheet used in the Zmanim Calendar Generator). Clicking on the link from the Zmanim tab will generate a calendar with the most typically used zmanim, while clicking on the link in the More Zmanim tab will download the full set of zmanim. These are available as the Calendar Type option in the Zmanim Calendar Generator.
  • Increased use of jQuery and jQuery UI for formatting the zmanim tables to better match the site look & feel.
  • Refactoring to make the code more robust and slightly more maintainable.
  • Time zones for all of Israel now display the time zone of Asia/Jerusalem as opposed to the Asia/Gaza returned for parts of Israel by the GeoNames TimeZone web service.

From a technical perspective there were a number of changes required due to updating the Google Maps API from v2 to v3. These include:

  • v3 no longer supports tabbed info windows, so the tabs are now implemented using jQuery UI.
  • Renaming of a number of classes and functions, such as GLatLng to LatLng.
  • A number of functions that were part of API v2 were removed in v3. One example is the latitude and longitude in radians that the v2 GLatLng class provided, which is not available in the v3 google.maps.LatLng class. These missing functions required for the direction to Yerushalayim calculations are now supported in the Zmanim Map using prototypes.

Bearing to Yerushalayim and Zmanim Map 2.0

Vintage Map with Compass

Update: The map implementation described in this post has been largely superseded. See the Zmanim Map 3.5 post (November 2012) and the ZmanimMap.com 4.0 post (November 2026) for the current map.

The availability of the Bearing to Yerushalayim and Zmanim Map was originally announced on December 30, 2007. At the time there were a number of bugs related to the Google Maps API. These bugs were reported to Google and eventually fixed. Since that time, the only change was a minor JavaScript fix for IE. The Bearing to Yerushalayim worked, but the zmanim tabs had a major issue because the time zone was calculated based on the user’s current browser time zone. This made it tricky to check zmanim in a different location or time zone than the user’s current time zone.Zmanim tab using time zonesI recently updated the map to look up the actual time zone of the latitude and longitude selected by the user. This was implemented by doing a lookup at the geonames.org time zone web service. The time zone is passed to the Zmanim API and used to generate the XML output of a list of daily zmanim that is displayed in the map. Since the Olson (now IANA) time zone database changes a few times a year, there will almost certainly be cases where the proper time zone can’t be determined. Some of these are changes of time zone names, such as the change from Asia/Calcutta to Asia/Kolkata (my host will not run the TZ Updater tool). In these cases, a simple mapping between the old and new was added to the map. In cases where the time zone can’t be determined, the time zone will default to UTC. Ocean locations within 10 km of land will use the closest landmass, but anywhere beyond 10 km will default to UTC. One issue with using the geonames.org web service is that when it is down, the map will time out. I experimented with various ways of dealing with this, but unless my host updates the Java version from 1.4, they are too complex to use at this time.

See the Technical Information about the Bearing to Yerushalayim Map post for technical details about the original implementation.

Calculating the Bearing/Direction to Har Habayis Using the Zmanim API

Vintage Map with CompassAn earlier “Bearing to Yerushalayim and Zmanim Map” post demonstrated the use of JavaScript to render the bearing to Har Habayis on a Google Map. A more detailed follow-up post “Technical Information about the Bearing to Yerushalayim Map” dealt with detailed technical information on these calculations. The main Bearing to Yerushalayim and Zmanim Map page usually has the most up-to-date information on the subject. What was not detailed in previously published posts and pages was that most of the calculations available via JavaScript are now in the core Zmanim API. Available since the July 2008 beta 2 release of version 1.1 is the ability to calculate bearings/directions using both the great circle and rhumb line methods in Java. The GeoLocation class was modified to calculate the great circle bearings (both initial and final), and rhumb line bearing from any GeoLocation object to another. In addition, distance calculation between the two points using both of these line types is supported. What was not ported from the JavaScript version was the less accurate Haversine formula, or the simpler spherical law of cosines algorithm that yields nearly identical results. Instead, the Zmanim API uses the far more accurate Vincenty formulae using the WGS84 ellipsoid model of the earth. Published by the geodesist/mathematician Thaddeus Vincenty, it is said to be accurate to about one-half millimeter, more than adequate for our calculation. The code in the API is a Java port of the previously published, slightly modified version of Chris Veness’s JavaScript implementation. Below is a simple Java example of generating bearing and distances.

Note: The code sample has been updated for the KosherJava Zmanim 3.x API, where GeoLocation takes a ZoneId instead of a TimeZone. The output shown below is from running it against version 3.1.0.
/**
 * This program demonstrates how to calculate bearing to Yerushalayim
 * using the kosherjava.com Zmanim API. Both the great circle and
 * rhumb line methods are shown.
 * To compile, ensure that the Zmanim jar is in your classpath.
 */
import com.kosherjava.zmanim.util.GeoLocation;
import java.time.ZoneId;

public class BearingToYerushalayim {
	public static void main(String[] args) {
		GeoLocation lakewood = new GeoLocation("Lakewood, NJ", 40.09596, -74.22213, 0, ZoneId.of("America/New_York"));
		GeoLocation harHabayis = new GeoLocation("Har Habayis", 31.77805, 35.235149, 0, ZoneId.of("Asia/Jerusalem"));

		double greatCircleInitialBearing = lakewood.getGeodesicInitialBearing(harHabayis);
		double greatCircleDistance = lakewood.getGeodesicDistance(harHabayis);

		double rhumbLineBearing = lakewood.getRhumbLineBearing(harHabayis);
		double rhumbLineDistance = lakewood.getRhumbLineDistance(harHabayis);

		System.out.println("Great circle initial bearing: " + greatCircleInitialBearing + " degrees");
		System.out.println("Great circle distance: " + greatCircleDistance / 1000 + " km");

		System.out.println("Rhumb line bearing: " + rhumbLineBearing + " degrees");
		System.out.println("Rhumb line distance: " + rhumbLineDistance / 1000 + " km");
	}
}

The output of the above code is:

Great circle initial bearing: 53.81786828306803 degrees
Great circle distance: 9244.617197329102 km
Rhumb line bearing: 95.37151951258849 degrees
Rhumb line distance: 9891.161030560183 km

Zmanim Calendar Generator TODO List

Sunrise CalendarI slightly updated the Zmanim Calendar Generator to add some user input validation.

Looking at the logs, I noticed that someone generated a calendar with the longitude and latitude of Lakewood, NJ (the default), with only the location label changed to Minneapolis, MN. I don’t know if the user was just testing or assumed that I picked up the geocoding information by parsing the location name. This led to the addition of a JavaScript confirmation when the location name is changed.

Items on the TODO list are:

  • Use JavaScript to convert the longitude and latitude when the format is changed from decimal to degrees, minutes and seconds
  • Provide links to locate longitude and latitude information
  • Add support for generating a standard calendar (not the full calendar, which is the current default) with a much smaller set of zmanim
  • Implement the generation of PDF calendars
  • Possibly use the Google Maps API to allow the selection of longitude and latitude information

The code for the PDF generation is already in the API, but it has not been updated in a while and does not work properly. It will also have to be updated for the standard calendar mentioned above.

The way I envision interacting with Google Maps is to let the user center their location on the map and have those coordinates used for the zmanim calendar. This would be relatively trivial if Google provided geocoding information, since the user could then enter their location as they do on Google Maps, but they currently do not provide geocoding information. I haven’t touched their API yet, and although it does not look too complex, it will probably take a while.