-1

I can't export and print the coordinates, the format of JSON is came from a query in a database the format is:

{"st_asgeojson":"{\"type\":\"LineString\",\"coordinates\":[[23.4582348,37.5062675],[23.4577141,37.5066109],[23.4572601,37.5070038],[23.4566746,37.507301],[23.455698,37.5076256],[23.4549737,37.5079214],[23.4545445,37.5080235],[23.4538579,37.5078873],[23.4531713,37.5077852],[23.4521842,37.5078533],[23.4513688,37.5079895],[23.4324646,37.5234265],[23.4324646,37.5236308],[23.4326363,37.5237669]]}"}

I try this code but I have not take anything:

JSON.parse(JSON.parse(jArray).st_asgeojson).coordinates.forEach(function(entry) { flightPlanCoordinates.push(new google.maps.LatLng(entry[1],entry[0])); });

I want to take the coordinates for example

23.4582348,37.5062675 23.4577141,37.5066109 23.4572601,37.5070038

Can anybody help me ?

2

Try parsing the JSON like this:

var json = {
    "st_asgeojson": {
        "type":"LineString",
        "coordinates":[
            [23.4582348,37.5062675],
            [23.4577141,37.5066109],
            [23.4572601,37.5070038],
            [23.4566746,37.507301],
            [23.455698,37.5076256],
            [23.4549737,37.5079214],
            [23.4545445,37.5080235],
            [23.4538579,37.5078873],
            [23.4531713,37.5077852],
            [23.4521842,37.5078533],
            [23.4513688,37.5079895],
            [23.4324646,37.5234265],
            [23.4324646,37.5236308],
            [23.4326363,37.5237669]
        ]
    }
}

var coords = json.st_asgeojson.coordinates;

coords.forEach(function(entry){
        flightPlanCoordinates.push(new google.maps.LatLng(entry[1],entry[0]));
});

Here's a real simple JSFIDDLE to show the parse works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.