dsaiztc
6/7/2014 - 10:27 AM

Converts NMEA GPS format to grades.

Converts NMEA GPS format to grades.

/**
	 * Converts a latitude/longitude in NMEA format to grades (4322.0399N to 43.36715)
	 * @param lat_or_long latitude/longitude in NMEA format
	 * @return GPS latitude/longitude in grades
	 */
	public static float convertLatLon(String lat_or_long)
	{
		int number_of_decimals = 4; // Número de decimales de los grados

		String minute = lat_or_long.substring(lat_or_long.length() - (4 + number_of_decimals), lat_or_long.length() - 1);
		float minutef = Float.parseFloat(minute);
		float minutef_grade = minutef / 60;
		String grade = lat_or_long.substring(0, lat_or_long.length() - (4 + number_of_decimals));
		float gradef = Float.parseFloat(grade);
		gradef += minutef_grade;

		char orientation = lat_or_long.charAt(lat_or_long.length() - 1);
		int positive = 0;
		switch (orientation)
		{
			case 'N':
			case 'E':
				positive = +1;
				break;
			case 'S':
			case 'W':
				positive = -1;
				break;
		}

		gradef *= positive;

		return gradef;
	}