我使用google map进行编程
var point1 = new GLatLng(24, 114);
然后使用
var lat1 = point1.latRadians();
怎么alert(lat1)为NAN
有什么错误吗?整个代码为:
说明:from1为24,114 to1为23,113都是正常的经纬度
function getDistance2(from, to, unit){
var from1 = from.replace("(","").replace(")","").trim();
var to1 = to.replace("(","").replace(")","").trim();
var point1 = new GLatLng(from1);
var point = new GLatLng(to1);
//地球半径
var R = 6378.137;
//千米英里转化
var M = 1.609344;
with(Math)
{
var lat1 = point1.latRadians();
//执行到这里就不能得到弧度的纬度
var lng1 = point1.lngRadians();
var lat2 = point.latRadians();
var lng2 = point.lngRadians();
var dist = 2 * asin(sqrt(pow((sin((lat1 - lat2)/2)), 2) + cos(lat1) * cos(lat2)
* pow((sin((lng1 - lng2) / 2)), 2))) * R;
}
if(unit=="M"){
dist = dist / M;
}
return dist;
}
var point1 = new GLatLng(from1);
http://code.google.com/intl/zh-TW/apis/maps/documentation/javascript/v2/reference.html#GLatLng
至少两个参数啊。纬度 经度
你的form1是这样子的?24.333,114.5555
那么需要分成两个参数啊
var temp= "24.333,114.5555";
var point1 = new GLatLng(temp.split(",")[0],temp.split(",")[1]);
简易分开纬度 经度 保存啊。以后有更方便的查询。(俺也做过google map开发)
你那個from to是什麽?
var from1 = from.replace("(","").replace(")","").trim();
var to1 = to.replace("(","").replace(")","").trim();
var point1 = new GLatLng(24, 114);
var lat1 = point1.latRadians();
沒有任何問題的
“你那個from to是什麽? ”
我这代码没问题啊。你用什么浏览器。
加个parseFloat试下
var point1 = new GLatLng(parseFloat(from1));