kostakondras Posted February 1, 2011 Share Posted February 1, 2011 I am attempting to create a Map on my web page that will have the directions (which will be dynamically pulled from a database) however I have been unable to find a good tutorial on how to achieve this, also there doesn't seem to be any PHP classes available out there (for free anyway) to create this easily. Any suggestions? Link to comment https://forums.phpfreaks.com/topic/226320-google-maps-api-directions/ Share on other sites More sharing options...
ttocskcaj Posted February 1, 2011 Share Posted February 1, 2011 http://code.google.com/apis/maps/documentation/javascript/ Don't think you could do it in php Link to comment https://forums.phpfreaks.com/topic/226320-google-maps-api-directions/#findComment-1168267 Share on other sites More sharing options...
salathe Posted February 1, 2011 Share Posted February 1, 2011 It's a fairly simply matter to use the Directions API with PHP. Here's an example which takes you down the Royal Mile in Edinburgh, Scotland. <?php $endpoint = 'http://maps.googleapis.com/maps/api/directions/json?'; $params = array( 'origin' => 'St Giles Cathedral, Edinburgh', 'destination' => 'Holyrood Palace, Edinburgh', 'mode' => 'walking', 'sensor' => 'false', ); // Fetch and decode JSON string into a PHP object $json = file_get_contents($endpoint.http_build_query($params)); $data = json_decode($json); // If we got directions, output all of the HTML instructions if ($data->status === 'OK') { $route = $data->routes[0]; foreach ($route->legs as $leg) { foreach ($leg->steps as $step) { echo $step->html_instructions . "<br>\n"; } } } Link to comment https://forums.phpfreaks.com/topic/226320-google-maps-api-directions/#findComment-1168276 Share on other sites More sharing options...
kostakondras Posted February 1, 2011 Author Share Posted February 1, 2011 Will this display the graphical map itself or simply the directional steps? Link to comment https://forums.phpfreaks.com/topic/226320-google-maps-api-directions/#findComment-1168290 Share on other sites More sharing options...
kostakondras Posted February 1, 2011 Author Share Posted February 1, 2011 Will this display the graphical map itself or simply the directional steps? And if not, is there a way to display the map along with the Directions? Link to comment https://forums.phpfreaks.com/topic/226320-google-maps-api-directions/#findComment-1168291 Share on other sites More sharing options...
salathe Posted February 1, 2011 Share Posted February 1, 2011 Will this display the graphical map itself... No, not at all. The code should be simple enough to see that it doesn't! If you just want the directions on a map, read the JavaScript API documentation. Which makes your request not a PHP question, but instead a JavaScript one. There likely are PHP functions/classes available to put a map onto a page, but they will just be writing the appropriate JavaScript rather than doing anything special or specific to PHP. Link to comment https://forums.phpfreaks.com/topic/226320-google-maps-api-directions/#findComment-1168299 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.