2016-11-15 59 views
2

我知道这可能是一个重复的问题。我已将它用Google搜索,但现在能够找到解决方案,这就是为什么我不得不在这里问这个问题。txtLatLong.split不是jQuery中的函数

我现在用leaflet.js工作得到一些地图和谷歌地图作为我的基地背景layer.here是我的脚本标签

<link rel="stylesheet" href="leaflet/leaflet.css"/> 
    <script src="leaflet/leaflet.js"></script> 
    <script src="leaflet/leaflet-src.js"></script> 
    <script src="leaflet/geoGson.js"></script> 
    <script src="js/jquery-1.10.2.min.js"></script> 
    <script src="./leaflet/locations/locationGeoGson.js"></script> 
    <script src="https://maps.googleapis.com/maps/api/js?key=MyKey async defer></script> 
    <script src='https://unpkg.com/[email protected]/Leaflet.GoogleMutant.js'></script> 

我的剧本是

var newLatLong=getMyCustomLayLong(latLong); 
function getMyCustomLayLong(txtLatLong){ 
    console.log("txtLatLong--"+txtLatLong.split(',')); 
    var cLong=txtLatLong.split(',')[0]; 
    var cLat=txtLatLong.split(',')[1]; 
    return cLat+','+cLat; 
} 

而我正在尝试将昏迷的字符串拆分成问题,请帮我解决。

回答

1
function getMyCustomLayLong(txtLatLong){ 
    var f_txtLatLong=txtLatLong+''; 
    var cLat=f_txtLatLong.split(',')[1]; 
    var cLong=f_txtLatLong.split(',')[0]; 
    return cLat+','+cLong; 
} 

这是对我而言的作品。

0

当sample为null或undefined时,sample.split不是函数。 我们无法拆分空值。所以错误会抛出。尝试在控制台中打印(console.log(txtLatLong))txtLatLong以查看其值。

+0

txtLatLong - 77.00234827943784,8.382997069681219这是我的控制台。 –

+2

似乎txtLatLong不是字符串 –

+0

是的可能会尝试在控制台中打印console.log(typeof txtLatLong)。这会给你一个变量类型。如果它的字符串没有转换为字符串前分裂 – Ashish451