Quantcast
Channel: Question and Answer » postgresql
Viewing all articles
Browse latest Browse all 1138

GeoJSON and php i cant visualy roads from postgres database

$
0
0

I am make a json file with geometry MultiLineString from the posgresql but when i try to load the file in map.data.loadGeoJsonis not visually the roads but if i take the link from google api example is show me the example i cant find why

Here is the code of script:

    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
    <script>
var map;
function initialize() {
  // Create a simple map.
  map = new google.maps.Map(document.getElementById('map-canvas'), {
    zoom: 4,
    center: {lat: 39.198205, lng: 26.228485}
  });

  // Load a GeoJSON from the same server as our demo.
  map.data.loadGeoJson('http://.../ways.json');
}

google.maps.event.addDomListener(window, 'load', initialize);

    </script>

Here is the code of php is make the json file:

<?php



   $result = pg_query($db, $sql);
   if(!$result){
      echo pg_last_error($db);
      exit;
   } 

// make JSON morfi

$geojson = array(
       'type'      => 'FeatureCollection',
       'features'  => array()
    ); 

   // Add edges to GeoJSON array

    while($row=pg_fetch_array($result)) {  
  $feature = array(
          'type' => 'Feature', 
          'geometry' => array(
             'type' => 'MultiLineString',
             'coordinates' => array($row[1],$row[2])

          ),
          'properties' => array(
            'gid' => $row[0]
            //'lenght' => $row[3],
           // 'dromoi' => $row[4]
           )
       );

       // Add feature array to feature collection array
       array_push($geojson['features'], $feature);

    }

   pg_close($db);
       file_put_contents('ways.json', json_encode($geojson));

?>

Viewing all articles
Browse latest Browse all 1138

Trending Articles