Software Developer

GeoNames Timezone Search Gives Wrong Latitude for Hamlet, Indiana

This page is in the Code Graveyard where I lay to rest snippets of code that I don't use anymore. Some have lost their usefulness due to the evolving nature of the web, while others have been replaced with better code. "Be Ye Warned!"

The Timezone web service from GeoNames has a little discrepancy that causes big problems for my app.

GeoNames Gives Wrong Latitude Degrees for Hamlet, Indiana.

Hamlet, Indiana latitude degrees according to GeoNames search = 41.5475442
Hamlet, Indiana latitude degrees according to Wikipedia = 41.381667

GeoNames’s incorrect latitude degrees throws my whole app off. I needed to get the timezone offset for a time in the past. For example, I needed to know the the timezone offset in Hamlet, Indiana in January of 1992. According to GeoNames Timezone search, the timezone offset in January is 6w. This is wrong. The actual timezone offset in Hamlet, Indiana for January of 1992 was 5w, not 6w.

Keep in mind that Hamlet, Indiana had convoluted time rule changes from 1991 – 2006.

So I tried using GeoNames Timezone search to only get the ‘Timezone Name’ of Hamlet, Indiana. Then I plugged that ‘Timezone Name’, along with my example time (1992-01-15 01:59) into a regular PHP function, timezone_offset_get, to get the timezone offset for January of 1992. But it still output the incorrect time offset for 1992 through 2006. The reason is GeoNames gives the incorrect timezone ID for Hamlet, Indiana.

According to GeoNames, the timezone ID for the coordinates that pertain to Hamlet, Indiana is ‘America/Chicago’. That’s wrong. The correct timezone for Hamlet, Indiana is ‘America/Indiana/Knox’ (according to Olson). But the real problem is not that GeoNames has the timezone ID wrong. Rather, GeoNames’s wrong latitude degrees for Hamlet is the problem.

See, when I feed Wikipedia’s latitude/longitude for Hamlet into GeoNames Timezone search, then the timezone ID comes up correctly as ‘America/Indiana/Knox’. Try it with the 2 sets of coordinates here:

1. Hamlet, Indiana coordinates according to GeoNames search = 41.5475442, -86.5822393
2. Hamlet, Indiana coordinates according to Wikipedia = 41.381667, -86.584722

I submitted to GeoNames an update to the Timezone for Hamlet, Indiana, but my app can’t afford discrepancies with other city timezone offsets. It may seem like a minor discrepancy, but my unique app relies on correct historic timezone data for GeoName’s coordinates.

So, my code to search GeoNames Timezone database goes into my code graveyard. (I still use GeoNames regular search to get coordinates. I figured out how to get the correct timezone offset of GeoNames’s coordinates from pure PHP. Will post later.)

R.I.P. GeoNames Timezone ID and offset search.

 * Get Timezone Information for a location based on latitude/longitude degrees
 * do var_dump($tzone) to see everything available
 * I use the Pear package here: Services_GeoNames
 * but...
 * This service is also available in JSON format :

require_once 'Services/GeoNames.php';//Include the Services_GeoNames package
$geo = new Services_GeoNames();

$tzone = $geo->timezone(
			// Hamlet Indiana according to Geonames search = 41.5475442 -86.5822393
			// Hamlet Indiana according to wiki = 41.381667, -86.584722
			'lat' => 41.5475442,// latitude degrees goes here
			'lng' => -86.7677663,// longitude degrees goes here

printf('Timezone id is: %s<br />
		Raw Offset is: %s<br />
		gmtOffset, which is timezone offset in January, is: %s<br />
		dstOffset, which is timezone offset in July, is: %s<br /><br /><hr />', $tzone->timezoneId, $tzone->rawOffset, $tzone->gmtOffset, $tzone->dstOffset);


Questions and Comments are Welcome

Your email address will not be published. All comments will be moderated.

Please wrap code in "code" bracket tags like this: