Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Take A QuizChallenge yourself and boost your learning! Start the quiz now to earn credits.
Take A QuizUnlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
Take A QuizKindly log in to use this feature. We’ll take you to the login page automatically.
LoginGeneral Tech Bugs & Fixes 3 years ago
User submissions are the sole responsibility of contributors, with TuteeHUB disclaiming liability for accuracy, copyrights, or consequences of use; content is for informational purposes only and not professional advice.
No matter what stage you're at in your education or career, TuteeHUB will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
Kindly log in to use this feature. We’ll take you to the login page automatically.
LoginReady to take your education and career to the next level? Register today and join our growing community of learners and professionals.
Your experience on this site will be improved by allowing cookies. Read Cookie Policy
Your experience on this site will be improved by allowing cookies. Read Cookie Policy
manpreet
Best Answer
3 years ago
I'm working with this source code. Html file (Openlayers + GeoExt) seems to work fine - everything shows up correctly but when I click on map nothing happend. I use my OSM data loaded to postregsql by osm2po. I think the problem is PHP file. I have changed it by myself but I'm almost sure I have made some mistake. Maybe somebody can help me to figured out what's wrong? Maybe the sql queries did errors? Any sugestions? I use PostgreSQL 9.5.3, PostGIS 2.2 and pgRouting 2.3.2. I'm not sure if my software version is comaptibile with used tutorial
PHP file:
// Database connection settings define("PG_DB", "ble"); define("PG_HOST", "localhost"); define("PG_USER", "postgres"); define("PG_PSSWD", "db_pass"); define("PG_PORT", "5432"); define("TABLE", "aa_2po_4pgr");// Retrieve start point $start = split(' ',$_REQUEST['startpoint']); $startPoint = array($start[0], $start1);
// Retrieve end point $end = split(' ',$_REQUEST['finalpoint']); $endPoint = array($end[0], $end1);
?>
// Find the nearest edge $startEdge = findNearestEdge($startPoint); $endEdge = findNearestEdge($endPoint); // FUNCTION findNearestEdge function findNearestEdge($lonlat) { // Connect to database $con = pg_connect("dbname=".PG_DB." host=".PG_HOST." port=".PG_PORT." user=".PG_USER." password=".PG_PSSWD) or die("nie udalo sie polaczyc z baza danych"); $sql = "SELECT id, source, target, geom_way, ST_distance(geom_way, ST_GeometryFromText( 'POINT(".$lonlat[0]." ".$lonlat[1].")', 4326)) AS dist FROM ".TABLE." WHERE geom_way( '(".($lonlat[0]-0.1)." ".($lonlat[1]-0.1).", ".($lonlat[0]+0.1)." ".($lonlat[1]+0.1).")') ORDER BY dist LIMIT 1"; $query = pg_query($con,$sql); $edge['id'] = pg_fetch_result($query, 0, 0); $edge['source'] = pg_fetch_result($query, 0, 1); $edge['target'] = pg_fetch_result($query, 0, 2); $edge['geom_way'] = pg_fetch_result($query, 0, 3); // Close database connection pg_close($con); return $edge; } ?>// Select the routing algorithm switch($_REQUEST['method']) {
} // close switch
// Connect to database $dbcon = pg_connect("dbname=".PG_DB." host=".PG_HOST." port=".PG_PORT." user=".PG_USER." password=".PG_PSSWD);
// Perform database query $query = pg_query($dbcon,$sql);
?>
'FeatureCollection', 'features' => array() ); // Add edges to GeoJSON array while($edge=pg_fetch_assoc($query)) { $feature = array( 'type' => 'Feature', 'geometry' => json_decode($edge['geojson'], true), 'crs' => array( 'type' => 'EPSG', 'properties' => array('code' => '4326') ), 'properties' => array( 'id' => $edge['id'], 'length' => $edge['length'] ) ); // Add feature array to feature collection array array_push($geojson['features'], $feature); } // Close database connection pg_close($dbcon); // Return routing result header('Content-type: application/json',true); echo json_encode($geojson); ?>After I lunch it in localhost (xampp) in browser i got this: