转换坐标串LAT多头排列谷歌地图API V3经度返回为0 [英] Converting string of coordinates to lat long array for google maps api v3 returning longitude as 0

查看:109
本文介绍了转换坐标串LAT多头排列谷歌地图API V3经度返回为0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经采取了看看其他所有的问题,但基本上,我有坐标一长串的,看起来像这样的字符串:42.2723998,-81.23239 ...... 42.84099,-81.3990398,我有使用JavaScript 。分裂( , );上,以便协调其现在称为数组[串各持一个坐标,然后用下面的code的]:

I've taken a look at all the other questions but basically, I have a long list of coordinates as a string that looks like this: "42.2723998, -81.23239 ... 42.84099, -81.3990398" which I have use javascript .split(" , "); on so that its now an array called coordinate[] of strings each holding one coordinate and then using the below code:

// create a coordinate Array
    var polygonCoords = [];
    // creates a new LatLng
    var j = 0;
    var z = j + 1;
while (z < coordinate.length) {
    if ((j%2) === 0) {
    var co1 = parseFloat(coordinate[z]);
    //document.write(coordinate[j]);
    var co2 = parseFloat(coordinate[j]);
    //document.write(co2);
    var newLatLng = new google.maps.LatLng(co1,co2);

    polygonCoords.push(newLatLng);
} else {
    var co2 = parseFloat(coordinate[z]);
    var co1 = parseFloat(coordinate[j]);
    var newLatLng = new google.maps.LatLng(co1,co2);
    polygonCoords.push(newLatLng);
}
    z++;
    j++;
    }

但是当我打印出来的polygonCoords阵列,它总是返回经度为0,我已经使用parseFloat分析也从一个字符串,以及()。此外,当我由它自己明确地返回的经度,它返回的实际数量。我只是需要它来工作,让我可以创建LatLngs数组,我可以为一个多边形的路径以后使用。

but when I print out the polygonCoords array, it always returns the longitude as 0 and I've also parsed it from a string as well using parseFloat(). Also when I explicitly return the longitude by its own, it returns the actual number. I just need it to work so that I can create an array of LatLngs that I can later use as a path for a polygon.

推荐答案

好吧,我固定它,不知何故,当我一把抓起KML文件的经度,这将是在0 -81.290390形式和...所以每当我解析它变成浮动,就认定其为0,而不是-81.293848。现在,它的正确完成,并打印出正确的彩车。

Ok, I've fixed it, somehow when I grabbed the longitude from the kml file, it would be in the form of 0 -81.290390... and so whenever i parsed it into float, it would recognize it as 0 instead of -81.293848. Now its done properly, and printing out the correct floats.

这篇关于转换坐标串LAT多头排列谷歌地图API V3经度返回为0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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