AMITKUMAR Posted October 20, 2016 Share Posted October 20, 2016 I am designing a Website of searching Buses stops and its timings i want to clear some concepts about how can i integrate Google Maps with my Database in PHP so that when i add some stops it will render from Google Maps and create a route pattern accordingly and saves to Database finally. for more clarity i have added a Pic only just need to clear concept i don't want coding's i will do it myself. Quote Link to comment https://forums.phpfreaks.com/topic/302364-need-help-to-clear-concept-of-google-maps-integration-in-php/ Share on other sites More sharing options...
Barand Posted October 20, 2016 Share Posted October 20, 2016 (edited) It looks like you have a lot of duplication of data. Every time you add a bus, you add the stops also. A better approach would be to define the route first. Route definition Stop +-----------+-----------+-----------+--------+ +----------+-----------------------+----------+-----------+ | route_id | sequence | stop_id | mins | | stop_id | stop name | Lat | Long | +-----------+-----------+-----------+--------+ +----------+-----------------------+----------+-----------+ | DA | 1 | 102 | 0 | | 101 | Agra | 27.16945 | 78.01194 | | DA | 2 | 103 | 10 | | 102 | Dehli | 28.60357 | 77.26217 | | DA | 3 | 104 | 190 | | 103 | Noida | etc | | DA | 4 | 101 | 250 | | 104 | Vrindavan | etc | +-----------+-----------+-----------+--------+ +----------+-----------------------+----------+-----------+ Now you can add the timetabled journeys to run on each route Timetabled journey +----------+-------------+----------+ | jny_id | route_id | depart | +----------+-------------+----------+ | 450 | DA | 7:50 | | 451 | DA | 9:50 | Intermediate stop times are then calculated from the route definition. You can take it further if you have a table to allocate the "bus working" defining the sets of journeys scheduled for a bus. This enables you to produce service timetable as well as vehicle timetables. To show on a map first create a map object. For each stop, create a LatLng object using the stop's latitude and longitude values add marker object to map object using the LatLng object [EDIT] Note that the above would be done in Javascript. You would use PHP to retrieve the data required and pass it to the client via an AJAX request. Edited October 20, 2016 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/302364-need-help-to-clear-concept-of-google-maps-integration-in-php/#findComment-1538427 Share on other sites More sharing options...
AMITKUMAR Posted October 20, 2016 Author Share Posted October 20, 2016 It looks like you have a lot of duplication of data. Every time you add a bus, you add the stops also. A better approach would be to define the route first. Route definition Stop +-----------+-----------+-----------+--------+ +----------+-----------------------+----------+-----------+ | route_id | sequence | stop_id | mins | | stop_id | stop name | Lat | Long | +-----------+-----------+-----------+--------+ +----------+-----------------------+----------+-----------+ | DA | 1 | 102 | 0 | | 101 | Agra | 27.16945 | 78.01194 | | DA | 2 | 103 | 10 | | 102 | Dehli | 28.60357 | 77.26217 | | DA | 3 | 104 | 190 | | 103 | Noida | etc | | DA | 4 | 101 | 250 | | 104 | Vrindavan | etc | +-----------+-----------+-----------+--------+ +----------+-----------------------+----------+-----------+ Now you can add the timetabled journeys to run on each route Timetabled journey +----------+-------------+----------+ | jny_id | route_id | depart | +----------+-------------+----------+ | 450 | DA | 7:50 | | 451 | DA | 9:50 | Intermediate stop times are then calculated from the route definition. You can take it further if you have a table to allocate the "bus working" defining the sets of journeys scheduled for a bus. This enables you to produce service timetable as well as vehicle timetables. To show on a map first create a map object. For each stop, create a LatLng object using the stop's latitude and longitude values add marker object to map object using the LatLng object [EDIT] Note that the above would be done in Javascript. You would use PHP to retrieve the data required and pass it to the client via an AJAX request. sir you suggested to show route on Map but i want to retrieve route information from Map so that all things like speed and distance of intermediate will come automatically only i have to feed stops and press ADD, if i do much calculation then all my time will be going to be wasted on adding Database, Quote Link to comment https://forums.phpfreaks.com/topic/302364-need-help-to-clear-concept-of-google-maps-integration-in-php/#findComment-1538441 Share on other sites More sharing options...
Barand Posted October 20, 2016 Share Posted October 20, 2016 https://developers.google.com/maps/documentation/distance-matrix/start Quote Link to comment https://forums.phpfreaks.com/topic/302364-need-help-to-clear-concept-of-google-maps-integration-in-php/#findComment-1538446 Share on other sites More sharing options...
Barand Posted October 21, 2016 Share Posted October 21, 2016 (edited) I haven't used the Google Distance Matrix API before so this was a learning exercise for me. Here's a small application: route_1.pgp - main page with map display route_2.php - responds to AJAX calls to retrieve data route.sql.txt - SQL script file to create database (Note mins and distances are set to zero in the route_definition table) When you load route_1, the routes are listed. Clicking on a route fetches the route definition from the database, submits a request to the google api to get the times and distances and updates the route records in the table. The distances and times are then listed on the screen and the stops are displayed on the map. I hope this helps to get you going. routes.sql.txt routes_1.php routes_2.php Edited October 21, 2016 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/302364-need-help-to-clear-concept-of-google-maps-integration-in-php/#findComment-1538471 Share on other sites More sharing options...
AMITKUMAR Posted October 22, 2016 Author Share Posted October 22, 2016 I haven't used the Google Distance Matrix API before so this was a learning exercise for me. Here's a small application: route_1.pgp - main page with map display route_2.php - responds to AJAX calls to retrieve data route.sql.txt - SQL script file to create database (Note mins and distances are set to zero in the route_definition table) When you load route_1, the routes are listed. Clicking on a route fetches the route definition from the database, submits a request to the google api to get the times and distances and updates the route records in the table. The distances and times are then listed on the screen and the stops are displayed on the map. I hope this helps to get you going. Great sir ! i am pleased that you get a topic to learn because of me btw i am getting a error while executing the Routes_1.php file " Fatal error: Call to a member function fetch_row() on boolean in C:\xampp\htdocs\yatrika\route1.php on line 13 " From where you are calling a Fetch Row Function ? Quote Link to comment https://forums.phpfreaks.com/topic/302364-need-help-to-clear-concept-of-google-maps-integration-in-php/#findComment-1538502 Share on other sites More sharing options...
Barand Posted October 22, 2016 Share Posted October 22, 2016 That would be because the query failed // get the google maps key $sql = "SELECT gm_key , ROUND(home_lat,2) , ROUND(home_long,2) FROM mydb.google_map_key"; $res = $db->query($sql); list($gmkey, $home_lat, $home_lng) = $res->fetch_row(); As the comment says, that query fetches my personal Google API key from a database (plus the starting map coordinates for the application. I suggest you provide those three values as hard-coded values for now to get it working. Remove the above code and replace with $home_lat = 27.60; $home_lng = 77.06; $gmkey = "<your api key goes here>"; I did some more testing today. "route_2" works only if the places on the route are on a straight route IE for A - B - C - D If you go off the line as in A - B D | | \ | C then it give the time for AD as less than the time AC. So the code needs changing so, instead of calculating AB, AC, AD as it does now, it calculates AB, BC, CD and accumulates the times. Revised route2 attached. routes_2.php Quote Link to comment https://forums.phpfreaks.com/topic/302364-need-help-to-clear-concept-of-google-maps-integration-in-php/#findComment-1538516 Share on other sites More sharing options...
AMITKUMAR Posted October 23, 2016 Author Share Posted October 23, 2016 I dont know why but after all error settled up its showing nothing on page also not updating database. Quote Link to comment https://forums.phpfreaks.com/topic/302364-need-help-to-clear-concept-of-google-maps-integration-in-php/#findComment-1538531 Share on other sites More sharing options...
Barand Posted October 23, 2016 Share Posted October 23, 2016 Check the browser console to see if the AJAX calls are behaving Quote Link to comment https://forums.phpfreaks.com/topic/302364-need-help-to-clear-concept-of-google-maps-integration-in-php/#findComment-1538534 Share on other sites More sharing options...
AMITKUMAR Posted October 24, 2016 Author Share Posted October 24, 2016 Check the browser console to see if the AJAX calls are behaving browser console also returning empty blank screen Quote Link to comment https://forums.phpfreaks.com/topic/302364-need-help-to-clear-concept-of-google-maps-integration-in-php/#findComment-1538559 Share on other sites More sharing options...
Barand Posted October 24, 2016 Share Posted October 24, 2016 Are any of the jQuery calls functioning? Quote Link to comment https://forums.phpfreaks.com/topic/302364-need-help-to-clear-concept-of-google-maps-integration-in-php/#findComment-1538560 Share on other sites More sharing options...
AMITKUMAR Posted October 24, 2016 Author Share Posted October 24, 2016 Are any of the jQuery calls functioning? Jquery doesn't calling routes_2.php debugger sowing routes_1.php only. Quote Link to comment https://forums.phpfreaks.com/topic/302364-need-help-to-clear-concept-of-google-maps-integration-in-php/#findComment-1538565 Share on other sites More sharing options...
Barand Posted October 24, 2016 Share Posted October 24, 2016 Does it work if you link to a local jquery.js file instead of the google one? Quote Link to comment https://forums.phpfreaks.com/topic/302364-need-help-to-clear-concept-of-google-maps-integration-in-php/#findComment-1538566 Share on other sites More sharing options...
AMITKUMAR Posted October 24, 2016 Author Share Posted October 24, 2016 Does it work if you link to a local jquery.js file instead of the google one? Nothing happen. is code working on your Localhost i am using XAMPP 5.6.3 [php: 7.0.3] XAMPP CP V3.2.2 Compiled Nov 12th 2015 also tested on XAMPP Version 5.6.20 Quote Link to comment https://forums.phpfreaks.com/topic/302364-need-help-to-clear-concept-of-google-maps-integration-in-php/#findComment-1538568 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.