convert string to coordinates RRS feed

  • Question

  • User736276958 posted

    Hi all

    How to convert string values into coordinates in js

    the values are not hardcoded, the values are coming dynamically.

    var payload = xs.serializeToString(node);

    In payload i am getting a xml file , everything is displaying correctly but only one tag is displaying as

    <posList>8571089.53392887 3553005.14086169 8571161.60495021 3553005.52437718 8575775.951427065 3552047.813669211 8571139.3550783 3552866.0537827 </posList>

    but i want this as 

    <posList>8571089.53392887,3553005.14086169,0 8571161.60495021,3553005.52437718,0 8575775.951427065,3552047.813669211,0 8571139.3550783,3552866.0537827,0 </posList>

    Friday, November 4, 2016 7:21 AM

All replies

  • User2009744128 posted

    Hi rishe28,

    You can replace the space characters with a comma of the entire string like this:

    var coordinateString="8588563.27859377 3558041.46968209 8588568.64897996 3558038.72500491 ";
    var coordinates=coordinateString.replace(/[ ]+/g,',');

    you can fetch the coordinates line by line by replacing the space character.

    Hope this helps

    Friday, November 4, 2016 7:37 AM
  • User1718973993 posted

    if the values are comming dynamically from the C# code behind then you can opt for this 

    string cordinateString=Regex.Replace(cordinateString, @"\s+",",");
    you may have to add
    using System.Text.RegularExpressions; namespace too 

    here the cordinateString="The raw input coordinate"
    cordinateString="The Returned string "

    Friday, November 4, 2016 7:43 AM
  • User347430248 posted

    Hi rishe28,

    if you just want to add comma in your string then other community member had already gave you a suggestion that you can use to replace the space with comma.

    here you can try to split your string and store it in array so that you can easily pass it when you need to pass coordinates.

    function coordinateStringToArray(coordinateString) {
                var sets = coordinateString.substr(1, coordinateString.length ).split(' ');
                var arr = new Array();
                for (i = 0; i < sets.length; ++i) {
                    var set = sets[i];
                    arr.push(new Array(set.substr(0,1), set.substr(2,1)));
                return arr;



    Monday, November 7, 2016 12:47 AM