Converting GPS coordinates to lat,long

Hi guys,

I have a database full of coordinates but they’re in the GPS format like this…

S25 48.518 E152 35.882

I need these coordinates converted to latitude and longitude values, but I can’t find any formula or function to do so. :confused: There’s hardly any information about this format available.

Has anyone had any experience with this GPS format?

Thanks! :smiley:

The scripts at GPS Coordinate Converter, Maps and Info seem to do it nicely. It’s the #1 listing in a [url=“http://www.google.co.nz/search?q=gps+coordinates”]gps coordinates search.

Additionally, if you don’t want to feel guilty about taking code from their web site, a search for javascript convert gps to latitude gives you as the #1 result [url=“http://www.movable-type.co.uk/scripts/latlong-gridref.html”]Convert between Latitude/Longitude & OS National Grid Reference points which provides you with a complete javascript function with which to do the conversions.

I thought I might be able to help until I noticed that you are using the Degree-minutes method. I have a script to convert between decimals and degree-minutes-seconds. But that won’t suit your needs.

Try looking at this:

http://www.divespots.com/scuba/storyID-40/viewStory.blogs

Near the bottom you can get a little idea of what you need to do.

Also, you never indicated which format you are trying to covert to. Degree-minutes-seconds (N35° 12’ 3.854’') or decimal (35.1245758). That’s important information.

Also see this:

WARNING: That script has a critical error. If you are converting from degrees-minutes-seconds to decimal (DMStoDEC), you must either strip the sign and append it back later (or determine sign using the directional indicator N, W, S, E) or subtract fractional decimals from the whole number for negative values or add for positive values or you will get an incorrect result!

The script has this line:


return $deg+((($min*60)+($sec))/3600);

You must either append a negative sign to the return value if a negative value was passed in (after first stripping it off) or do something like this:


$fractional_part = (($min * 60) + $sec) / 3600;

		if ($deg < 0)
		{
			$dec = $deg - $fractional_part;
		}
		elseif ($deg > 0)
		{
			$dec = $deg + $fractional_part;
		}

		return $dec;