2017-10-07 82 views
3

我想將字符串轉換爲latlng假設字符串是23.097278,72.446139我想將它轉換爲latlng,當我拆分字符串時我得到的結果是我想要的,但是當我轉換爲latlng時它會在座標末尾附加一些數字 例如 centerPoint:(23.081295,72.49794399999996),到目前爲止我所做的是在plz下面幫我解決它。離子: - 將字符串轉換爲latlng在最後附加更多數字?

temp="23.097278,72.446139"; 
let temp1 = temp.split(','); 

let coordinatesLat = temp1[0]; 
let coordinatesLong = temp1[1]; 

console.log("temp1 : " +coordinatesLong); 

let centerPoint = new google.maps.LatLng(coordinatesLat, coordinatesLong); 
console.log("centerPoint : " +centerPoint); 

在日誌

temp1 : 72.497944 
centerPoint : (23.081295, 72.49794399999996) 

回答

0

嘗試轉換輸出到浮動

變種latDouble = parseFloat(LAT); var longDouble = parseFloat(long);

+0

無法使用此代碼 –