Created
December 4, 2016 05:51
-
-
Save chibiegg/1b3d7d6c49fd05e5fef6127d3d06e57d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> | |
<script type="text/javascript"> | |
$(function(){ | |
function convert(){ | |
// 345116N1360617E | |
// 34°51'16"136°06'17" | |
var lonlat = $("#lonlat").val(); | |
console.log("input: " + lonlat); | |
if(lonlat.length != 15){ | |
return; | |
} | |
var result = ""; | |
result += lonlat.slice(0, 2); | |
result += "°"; | |
result += lonlat.slice(2, 4); | |
result += "'"; | |
result += lonlat.slice(4, 6); | |
result += "\""; | |
result += lonlat.slice(7, 10); | |
result += "°"; | |
result += lonlat.slice(10, 12); | |
result += "'"; | |
result += lonlat.slice(12, 14); | |
result += "\""; | |
console.log("output: " + result); | |
$("#out_lonlat").val(result); | |
} | |
$("#lonlat").val("345116N1360617E"); | |
convert(); | |
$("#lonlat").change(convert); | |
$("#lonlat").keypress(convert); | |
}); | |
</script> | |
</head> | |
<body> | |
<div> | |
<input type="text" id="lonlat" value=""> | |
</div> | |
<div> | |
<input type="text" id="out_lonlat" value=""> | |
</div> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment