// nilab.geo
var nilab = {};
nilab.geo = {};

nilab.geo.Utils = {
//var info_nilab_GeoUtils = {

	a : "ぐわ",

	// Ref. Mac･GPS･Perl - 測地系の変換方法
	//      http://homepage3.nifty.com/Nowral/02_DATUM/02_DATUM.html#HowTo
	tokyo_to_wgs84 : function(lat, lon){
		var latlon = new Object();
		latlon.lat = lat - 0.00010695 * lat + 0.000017464 * lon + 0.0046017;
		latlon.lon = lon - 0.000046038 * lat - 0.000083043 * lon + 0.010040;
		return latlon;
	},

	// Ref. Mac･GPS･Perl - 測地系の変換方法
	//      http://homepage3.nifty.com/Nowral/02_DATUM/02_DATUM.html#HowTo
	wgs84_to_tokyo : function(lat, lon){
		var latlon = new Object();
		latlon.lat = lat + 0.00010696 * lat - 0.000017467 * lon - 0.0046020;
		latlon.lon = lon + 0.000046047 * lat + 0.000083049 * lon - 0.010041;
		return latlon;
	},

	wgs84_to_locapoint : function(lat, lon){
		var obj = new Object();
		obj.latitude  = lat;
		obj.longitude = lon;
		return _LatLon2LocaPoint(obj);
	},

	// Ref. LocaPoint Specification
	//      http://www.locapoint.com/en/samplecode.html#JS_code
	_LatLon2LocaPoint : function(location){

		var latitude_step = (location.latitude + 90)/180*45697600;
		var longitude_step = (location.longitude + 180)/360*45697600;

		// fromCharCode <-> fontCharCode?
		var locapoint = String.fromCharCode(
			latitude_step/1757600%26 + 65,
			latitude_step/67600%26 + 65,
			latitude_step/6760%10 + 48,
			46,
			longitude_step/1757600%26 + 65,
			longitude_step/67600%26 + 65,
			longitude_step/6760%10 + 48,
			46,
			latitude_step/260%26 + 65,
			latitude_step/10%26 + 65,
			latitude_step/1%10 + 48,
			46,
			longitude_step/260%26 + 65,
			longitude_step/10%26 + 65,
			longitude_step/1%10 + 48
			);

		return(locapoint);
	}

};
