|
1 | 1 | # PHP Simple Google Maps |
2 | 2 |
|
| 3 | +[](https://github.styleci.io/repos/159809368) |
| 4 | + |
3 | 5 | This package provides a simple PHP client for various Google Maps APIs. |
4 | 6 |
|
5 | 7 | ## Installation |
@@ -67,3 +69,63 @@ $address = $simpleGoogleMaps->reverseGeocode(new LatLong(51.5033635, -0.1276248) |
67 | 69 | This method will return a string containing the address found at the specified coordinates. If no address |
68 | 70 | could be found, `null` will be returned. |
69 | 71 |
|
| 72 | +### Directions |
| 73 | + |
| 74 | +To find the directions between two points, use the `directions` method. The methods expects |
| 75 | +three parameters, the origin, the destination, and optionally the travel mode as defined by the |
| 76 | +`TravelMode` enum. |
| 77 | + |
| 78 | +See the example usage below. |
| 79 | + |
| 80 | +```php |
| 81 | +$address1 = "10 Downing St, Westminster, London SW1A UK"; |
| 82 | +$address2 = "Schott House, Drummond Rd, Stafford ST16 3EL"; |
| 83 | + |
| 84 | +$journey = $simpleGoogleMaps->directions($address1, $address2, TravelMode::DRIVING); |
| 85 | + |
| 86 | +foreach($journey as $step) { |
| 87 | + echo $step->duration.' secs '; |
| 88 | + echo "\t"; |
| 89 | + echo $step->distance.' m '; |
| 90 | + echo "\t"; |
| 91 | + echo $step->description; |
| 92 | + echo PHP_EOL; |
| 93 | +} |
| 94 | + |
| 95 | +echo 'Totals: '.$journey->duration().' secs, '.$journey->distance().' km'; |
| 96 | +echo PHP_EOL; |
| 97 | +``` |
| 98 | + |
| 99 | +This will produce output similar to the following. |
| 100 | + |
| 101 | +``` |
| 102 | +134 secs 452 m Head north on Whitehall / A3212 toward Horse Guards Ave May be closed at certain times or days |
| 103 | +203 secs 1029 m At the roundabout, take the 1st exit onto The Mall Parts of this road may be closed at certain times or days |
| 104 | +121 secs 688 m Turn right onto Constitution Hill |
| 105 | +34 secs 141 m Turn left onto Duke of Wellington Pl Leaving toll zone |
| 106 | +20 secs 83 m Turn right onto Grosvenor Pl |
| 107 | +21 secs 107 m Slight right onto Piccadilly May be closed at certain times or days |
| 108 | +164 secs 1244 m Slight left onto Park Ln / A4202 |
| 109 | +35 secs 199 m Slight left onto Cumberland Gate |
| 110 | +16 secs 68 m Turn right onto Bayswater Rd |
| 111 | +92 secs 410 m Slight left onto Edgware Rd / A5 Entering toll zone in 280 m at Upper Berkeley St Leaving toll zone in 300 m at Stourcliffe St |
| 112 | +48 secs 177 m Turn right onto George St Entering toll zone |
| 113 | +152 secs 531 m Turn left onto Seymour Pl |
| 114 | +46 secs 231 m Turn left onto Marylebone Rd / A501 Leaving toll zone |
| 115 | +722 secs 9209 m Keep right to continue on Marylebone Flyover / A40 Continue to follow A40 |
| 116 | +708 secs 14581 m Keep right to continue on Western Ave / A40 |
| 117 | +4636 secs 140047 m Keep right to continue on M40 , follow signs for M25 / Birmingham / Oxford / Beaconsfield |
| 118 | +49 secs 1164 m At junction 3A , take the M42 / Railway Station / Airport exit to M1 / M6 / Birmingham (E, N & C) / Solihull / N.E.C. |
| 119 | +856 secs 22091 m Merge onto M42 |
| 120 | +14 secs 375 m Keep right at the fork to continue on M6 Toll |
| 121 | +1121 secs 33363 m Keep right at the fork to stay on M6 Toll Toll road |
| 122 | +756 secs 19905 m Continue onto M6 |
| 123 | +23 secs 206 m At junction 14 , take the A34 exit to Stone / Stafford (N) |
| 124 | +103 secs 1213 m At the roundabout, take the 3rd exit onto A34 Go through 1 roundabout |
| 125 | +80 secs 925 m At the roundabout, take the 2nd exit onto Beaconside / A513 |
| 126 | +128 secs 1550 m Turn right onto Common Rd |
| 127 | +13 secs 123 m Turn left onto Astonfields Rd |
| 128 | +76 secs 395 m Turn left onto Drummond Rd Destination will be on the left |
| 129 | +Totals: 10371 secs, 250507 km |
| 130 | +``` |
| 131 | + |
0 commit comments