Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I try to make a dikstra pgrouting query in a php file i retrive the coordinates and pass them in the Javascript code as o JSON object and visual in the map use this Script from google api to draw the line

first heare is the query from php file

$sql ="SELECT seq , id1 AS node, id2 AS edge, cost , ST_AsGeoJSON(b.geom), gid AS id FROM pgr_dijkstra('
                    SELECT gid AS id,
                             source::integer,
                             target::integer,
                             shape_leng::double precision AS cost
                            FROM roads',
                    '". $start ." ','". $end ."', false, false)  a LEFT JOIN roads b ON (a.id2 = b.gid);";

       $result = pg_query($db,$sql);

      $Arresu = array();
      $ArPhp = array();
    while ($row = pg_fetch_row($result, null, PGSQL_ASSOC)) {   
    $Arresu []= $row['st_asgeojson'];
    }  
    $ArPhp = json_encode($Arresu);

after in Javascript i want to push all cordinates in the array flightPlanCoordinates and after to visual in google map.

var jsonAr= <?php echo json_decode($ArPhp); ?>;

     var arr = JSON.parse(jsonAr);
     var flightPlanCoordinates = [];
     var map;
     var flightPath;

 var arrLeng = arr.length;
   for (var i = 0; i < arrLeng; i++) {
    var coordArray = JSON.parse(JSON.parse(arr[i].st_asgeojson).coordinates;
    var coordArrLeng = coordArray.length;
    for (var j = 0; j < coordArrLeng; j++) {
        var coords = coordArray[0][0];
        var coordLeng = coords.length;
        for (var k = 0; k < coordLeng; k++) {
          flightPlanCoordinates.push(new google.maps.LatLng(coords[k]));
        }
    }
}

but i have problem in to fill the array with coordinates

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.