Return to Snippet

Revision: 21959
at December 26, 2009 17:54 by ginoplusio


Initial Code
function convertDecDeg(v,tipo) {
	if (!tipo) tipo='N';
	var deg;
	deg = v;
	if (!deg){
		return "";
	} else if (deg > 180 || deg < 0){
		// convert coordinate from north to south or east to west if wrong tipo
		return convertDecDeg(-v,(tipo=='N'?'S': (tipo=='E'?'W':tipo) ));
	} else {
		var gpsdeg = parseInt(deg);
		var remainder = deg - (gpsdeg * 1.0);
		var gpsmin = remainder * 60.0;
		var D = gpsdeg;
		var M = parseInt(gpsmin);
		var remainder2 = gpsmin - (parseInt(gpsmin)*1.0);
		var S = parseInt(remainder2*60.0);
		return D+"&deg; "+M+"' "+S+"'' "+tipo;
	}
}

Initial URL
http://www.barattalo.it/2009/12/26/decimal-degrees-conversion-and-distance-of-two-points-on-google-map/

Initial Description
When you show the coordinates of a point, it’s sometimes better to show them as degrees and not as deciaml (even if decimal is simpler). Each of the two coordinates can be converted with the same function. In the function call the “tipo” is the type of the “v” value: if you call the function without the type, then the default type is “N”, that means “NORTH”, it means that you’re converting a Latitude value. Values for latitude type are “N” for NORTH and “S” for SOUTH.
If you specify “E” or “W” than you’re converting a Longitude value.

Initial Title
Javascript decimal to degrees for google maps

Initial Tags
javascript, google

Initial Language
JavaScript