Convert String to latlng google maps

后端 未结 2 1695
野趣味
野趣味 2021-01-17 16:20

I want to convert a String with a pattern like \"(53.324523, 43.252352)\" into a latlng. I already found the right function:

var input = latlngArray[i];
var          


        
相关标签:
2条回答
  • 2021-01-17 17:02

    Quick fix after var input. Looks like the '(' is messing up the lat conversion:

    input = input.replace('(','');
    
    0 讨论(0)
  • 2021-01-17 17:02

    A general solution can be:

    var locationToStringed = "(53.324523, 43.252352)";
    var input = locationToStringed.replace('(', '');
    var latlngStr = input.split(",", 2);
    var lat = parseFloat(latlngStr[0]);
    var lng = parseFloat(latlngStr[1]);
    var parsedPosition = new google.maps.LatLng(lat, lng);
    
    0 讨论(0)
提交回复
热议问题