Ejemplo n.º 1
0
 public function GenerateMap($first = '', $second = '')
 {
     if ($first == '') {
         $first = 'mannheim';
     }
     $address1 = $first;
     $prepAddr1 = str_replace(' ', '+', $address1);
     $geocode1 = file_get_contents('http://maps.google.com/maps/api/geocode/json?address=' . $prepAddr1 . '&sensor=false');
     $output1 = json_decode($geocode1);
     $latitude1 = $output1->results[0]->geometry->location->lat;
     $longitude1 = $output1->results[0]->geometry->location->lng;
     if ($second == '') {
         $second = 'berlin';
     }
     $address2 = $second;
     $prepAddr2 = str_replace(' ', '+', $address2);
     $geocode2 = file_get_contents('http://maps.google.com/maps/api/geocode/json?address=' . $prepAddr2 . '&sensor=false');
     $output2 = json_decode($geocode2);
     $latitude2 = $output2->results[0]->geometry->location->lat;
     $longitude2 = $output2->results[0]->geometry->location->lng;
     $coord = new LatLng(['lat' => $latitude1, 'lng' => $longitude1]);
     $map = new Map(['center' => $coord, 'zoom' => 14]);
     // lets use the directions renderer
     $home = new LatLng(['lat' => $latitude1, 'lng' => $longitude1]);
     $school = new LatLng(['lat' => $latitude2, 'lng' => $longitude2]);
     $directionsRequest = new DirectionsRequest(['origin' => $home, 'destination' => $school, 'travelMode' => TravelMode::DRIVING]);
     // Lets configure the polyline that renders the direction
     $polylineOptions = new PolylineOptions(['strokeColor' => '#FFAA00', 'draggable' => true]);
     // Now the renderer
     $directionsRenderer = new DirectionsRenderer(['map' => $map->getName(), 'polylineOptions' => $polylineOptions]);
     // Finally the directions service
     $directionsService = new DirectionsService(['directionsRenderer' => $directionsRenderer, 'directionsRequest' => $directionsRequest]);
     // Thats it, append the resulting script to the map
     $map->appendScript($directionsService->getJs());
     return $map;
 }
Ejemplo n.º 2
0
use dosamigos\google\maps\layers\BicyclingLayer;
$coord = new LatLng(['lat' => 16, 'lng' => 100]);
$map = new Map(['center' => $coord, 'zoom' => 8]);
// lets use the directions renderer
$home = new LatLng(['lat' => 15.9, 'lng' => 99.91180171966555]);
$school = new LatLng(['lat' => 39.719456079114956, 'lng' => 2.8979293346405166]);
$santo_domingo = new LatLng(['lat' => 39.72118906848983, 'lng' => 2.907628202438368]);
// setup just one waypoint (Google allows a max of 8)
$waypoints = [new DirectionsWayPoint(['location' => $santo_domingo])];
$directionsRequest = new DirectionsRequest(['origin' => $home, 'destination' => $school, 'waypoints' => $waypoints, 'travelMode' => TravelMode::DRIVING]);
// Lets configure the polyline that renders the direction
$polylineOptions = new PolylineOptions(['strokeColor' => '#FFAA00', 'draggable' => true]);
// Now the renderer
$directionsRenderer = new DirectionsRenderer(['map' => $map->getName(), 'polylineOptions' => $polylineOptions]);
// Finally the directions service
$directionsService = new DirectionsService(['directionsRenderer' => $directionsRenderer, 'directionsRequest' => $directionsRequest]);
// Thats it, append the resulting script to the map
$map->appendScript($directionsService->getJs());
// Lets add a marker now
$marker = new Marker(['position' => $coord, 'title' => 'My Home Town']);
// Provide a shared InfoWindow to the marker
$marker->attachInfoWindow(new InfoWindow(['content' => '<p>ทดสอบ</p>']));
// Add marker to the map
$map->addOverlay($marker);
// Now lets write a polygon
$coords = [new LatLng(['lat' => 25.774252, 'lng' => -80.190262]), new LatLng(['lat' => 18.466465, 'lng' => -66.118292]), new LatLng(['lat' => 32.321384, 'lng' => -64.75736999999999]), new LatLng(['lat' => 25.774252, 'lng' => -80.190262])];
$polygon = new Polygon(['paths' => $coords]);
// Add a shared info window
$polygon->attachInfoWindow(new InfoWindow(['content' => '<p>This is my super cool Polygon</p>']));
// Add it now to the map
$map->addOverlay($polygon);