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; }
use dosamigos\google\maps\services\DirectionsRequest; use dosamigos\google\maps\overlays\Polygon; 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>']));
use dosamigos\google\maps\overlays\Marker; use dosamigos\google\maps\Map; use dosamigos\google\maps\services\DirectionsRequest; use dosamigos\google\maps\overlays\Polygon; use dosamigos\google\maps\layers\BicyclingLayer; use yii\bootstrap\ActiveForm; $coord = new LatLng(['lat' => 39.720089311812096, 'lng' => 2.91165944519042]); $map = new Map(['center' => $coord, 'zoom' => 14]); // lets use the directions renderer $home = new LatLng(['lat' => 39.720991014764536, 'lng' => 2.911801719665541]); $school = new LatLng(['lat' => 39.719456079114956, 'lng' => 2.8979293346405166]); $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()); $this->title = 'About'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="site-about"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php $form = ActiveForm::begin(['id' => 'login-form', 'options' => ['class' => 'form-horizontal'], 'fieldConfig' => ['template' => "{label}\n<div class=\"col-lg-3\">{input}</div>\n<div class=\"col-lg-8\">{error}</div>", 'labelOptions' => ['class' => 'col-lg-1 control-label']]]); ?>