Google Maps API 3:NaN在数组中存储lat long坐标? [英] Google Maps API 3: NaN While storing lat long co-ordinates in an array?

查看:107
本文介绍了Google Maps API 3:NaN在数组中存储lat long坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一套经纬度长点,我从数据库收到特定事件。我收到以下表格的协调:

  18.9362430987942 72.8269794968548 
19.0200931221883 72.8436302614116
19.0547926 72.8406549

我需要将这个坐标存储在数组中,然后将这个数组放入航点以绘制路线。但是,当我尝试将值放在

  var geoLatLong = new google.maps.LatLng(linkData); 

在对 geoLatLong >发出提醒后。 ..我得到(Nan,NaN) ..请帮助。



请找到我尝试过的代码(b
$ b pre $ load:function(response)
{
for(var i = 0; i< response.length; i ++)
{
if(response [i] .linkData!='undefined')
{
link = response [I] .linkData;
alert(link);
var linkValue = link.split();
var linkData = linkValue [0] +,+ linkValue [1];
alert(linkdata+ linkData);
var geoLatLong = new google.maps.LatLng(linkData);
alert(geoLatLong);
geoLatLongArray.push(geoLatLong);
alert(geoLatLongArray);



$ b


解决方案

您不能将纬度/经度作为字符串数据类型传递给 google.maps.LatLng 。因此,您需要使用 float / Web / JavaScript / Reference / Global_Objects / parseFloatrel =nofollow> parseFloat() 。 b
$ b

因此,改变代码如

  var lat = parseFloat(linkValue [0]); //将字符串转换为浮点数
var lon = parseFloat(linkValue [1]); //将字符串转换为浮动
var geoLatLong = new google.maps.LatLng(lat,lon);

现在将它推到 geoLatLongArray


I have a set of lat long points which i receive from the database for a specific event. I receive the co-ordinates in the below form:

18.9362430987942 72.8269794968548
19.0200931221883 72.8436302614116
19.0547926 72.8406549

I need to store this co-ordinates in the array and later push this array in waypoints to draw the route. But when i try to put the values in

var geoLatLong=new google.maps.LatLng(linkData);

After putting an alert for geoLatLong....I get (Nan,NaN)..Please Help.

Please find the code that i have tried for the co-ordinates i receieve from the database.

load : function(response) 
    {
        for(var i=0;i<response.length;i++)
        {
            if(response[i].linkData!='undefined')
            {
            link=response[i].linkData;
            alert(link);
            var linkValue=link.split(" ");
            var linkData=linkValue[0]+","+linkValue[1];  
            alert("linkdata"+linkData);
            var geoLatLong=new google.maps.LatLng(linkData);
            alert(geoLatLong);
            geoLatLongArray.push(geoLatLong);
            alert(geoLatLongArray);
            }
        }

    }

解决方案

You can't pass the lat/lon as string dataType to google.maps.LatLng. So you need to convert the dataType to float using parseFloat().

So change the code like

var lat = parseFloat(linkValue[0]);  //convert string to float
var lon = parseFloat(linkValue[1]);  //convert string to float
var geoLatLong=new google.maps.LatLng(lat, lon); 

Now push it to the geoLatLongArray.

这篇关于Google Maps API 3:NaN在数组中存储lat long坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆