<!-- create by xtzh, 2007-05-22 -->
<html>
<head>
<title>灵图编码、经纬度互转</title>
</head>
<center><b>灵图编码 <--> 经纬度</b><hr>
<form>
<table border=1 align=center width=85%>
<tr><td align=right>
灵图编码:
</td><td>
<input type=text name="ltbm" maxlength=14 onkeyup='ltm2jwd(this.form)'> [xxxx-xxxx-xxxx]
</td></tr>
<tr><td align=right>
经度:
</td><td>
<input type=text name="jd" maxlength=8 onkeyup='jwd2ltm(this.form)'> [xxx.xxxx]
</td></tr>
<tr><td align=right>
纬度:
</td><td>
<input type=text name="wd" maxlength=7 onkeyup='jwd2ltm(this.form)'> [xx.xxxx]
</td></tr>
</table>
<table border=0 width=100%>
<tr>
<td align=right>
<input type=button value="转换" onclick='calc(this.form)'>
</td>
<td> </td>
<td allign=left>
<input type=reset value="清除">
</td>
</tr>
</table>
</form>
</html>
<script language=javascript>
function calc(theForm)
{
if(theForm.ltbm.value.length>0)
{
if(theForm.ltbm.value.length!=14)
{
alert("[灵图编码] 格式错");
return false;
}
ltm2jwd(theForm);
return false;
}
if(theForm.jd.value.length>0 && theForm.wd.value.length>0)
{
jwd2ltm(theForm);
return false;
}
}
function ltm2jwd(theForm)
{
if(theForm.ltbm.value.length!=14)
{
theForm.jd.value="";
theForm.wd.value="";
return false;
}
var longitude,latitude;
if(theForm.ltbm.value.charAt(13)<'5') longitude="1" + theForm.ltbm.value.charAt(13);
else longitude = theForm.ltbm.value.charAt(13);
longitude = longitude + theForm.ltbm.value.charAt(7) + ".";
longitude = longitude + theForm.ltbm.value.charAt(8);
longitude = longitude + theForm.ltbm.value.charAt(2);
longitude = longitude + theForm.ltbm.value.charAt(6);
longitude = longitude + theForm.ltbm.value.charAt(10);
latitude = theForm.ltbm.value.charAt(11);
latitude = latitude + theForm.ltbm.value.charAt(1) + ".";
latitude = latitude + theForm.ltbm.value.charAt(12);
latitude = latitude + theForm.ltbm.value.charAt(5);
latitude = latitude + theForm.ltbm.value.charAt(0);
latitude = latitude + theForm.ltbm.value.charAt(3);
if(isNaN(longitude) || isNaN(latitude) || theForm.ltbm.value.charAt(4)!='-' || theForm.ltbm.value.charAt(9)!='-')
{
alert("[灵图编码] 格式错");
return false;
}
else
{
theForm.jd.value=longitude;
theForm.wd.value=latitude;
}
return false;
}
function jwd2ltm(theForm)
{
if(theForm.jd.value.length==0 || isNaN(theForm.jd.value) || theForm.wd.value.length==0 || isNaN(theForm.wd.value))
{
theForm.ltbm.value = "";
return false;
}
var longitude,latitude;
var str1,str2;
longitude = parseFloat(theForm.jd.value);
latitude = parseFloat(theForm.wd.value);
if(longitude>180 || longitude<0)
{
alert("[经度] 数值错");
return false;
}
if(latitude>90 || latitude<0)
{
alert("[纬度] 数值错");
return false;
}
else
{
if(longitude>=100) longitude-=100;
longitude *= 10000;
latitude *= 10000;
str1 = longitude.toString();
str2 = latitude.toString();
if(str2.length<6) str2 = "0" + str2;
theForm.ltbm.value = str2.charAt(4);
theForm.ltbm.value += str2.charAt(1);
theForm.ltbm.value += str1.charAt(3);
theForm.ltbm.value += str2.charAt(5);
theForm.ltbm.value += "-";
theForm.ltbm.value += str2.charAt(3);
theForm.ltbm.value += str1.charAt(4);
theForm.ltbm.value += str1.charAt(1);
theForm.ltbm.value += str1.charAt(2);
theForm.ltbm.value += "-";
theForm.ltbm.value += str1.charAt(5);
theForm.ltbm.value += str2.charAt(0);
theForm.ltbm.value += str2.charAt(2);
theForm.ltbm.value += str1.charAt(0);
}
return false;
}
</script>
灵图坐标转换
5星 · 超过95%的资源 需积分: 0 111 浏览量
2008-08-02
11:38:57
上传
评论
收藏 949B RAR 举报
农户的空间
- 粉丝: 1
- 资源: 16
评论1