Open pedroriverove opened 7 years ago
The only thing you need to do is to create a LatLngBounds which is compound of two LatLng. Then create a Rectangle
providing the newly created LatLngBounds instance to its bounds option on its constructor (as an option).
Then add the rectangle to the map exactly
as you do with a marker.
Ok thank you very much for the explanation Could you see my code to see what I'm failing? Thank you very much.
$coord = new LatLng(['lat' => -1.831239, 'lng' => -78.18340599999999]);
$map = new Map([
'center' => $coord,
'zoom' => 7,
]);
$waypoints = [
new LatLngBounds([
new LatLng(['lat' => -1.743391143288001, 'lng' => -79.98516381249999]),
new LatLng(['lat' => -1.1672520205625432, 'lng' => -76.98516381249999]),
])
];
$rectangleOptions = new RectangleOptions([
'fillColor' => '#00FF00',
'strokeColor' => 'red',
'draggable' => true,
'editable' => true,
]);
$map->appendScript($rectangleOptions->getJs());
$marker = new Marker([
'position' => $coord,
'title' => 'My Home Town',
]);
$marker->attachInfoWindow(
new InfoWindow([
'content' => '<p>This is my super cool content</p>'
])
);
$rectangle = new Rectangle([
'paths' => $waypoints
]);
$map->addOverlay($rectangle);
$bikeLayer = new BicyclingLayer(['map' => $map->getName()]);
$map->appendScript($bikeLayer->getJs());
echo $map->display();
Rectangle extends from RectangleOptions: https://github.com/2amigos/yii2-google-maps-library/blob/master/overlays/Rectangle.php#L25
$coord = new LatLng(['lat' => -1.831239, 'lng' => -78.18340599999999]);
$map = new Map([
'center' => $coord,
'zoom' => 7,
]);
$marker = new Marker([
'position' => $coord,
'title' => 'My Home Town',
]);
$marker->attachInfoWindow(
new InfoWindow([
'content' => '<p>This is my super cool content</p>'
])
);
// add marker
$map->addOverlay($marker);
// create rectangle
$bounds = new LatLngBounds([
new LatLng(['lat' => -1.743391143288001, 'lng' => -79.98516381249999]),
new LatLng(['lat' => -1.1672520205625432, 'lng' => -76.98516381249999]),
]);
$rectangle = new Rectangle([
'bounds' => $bounds, // here my bounds!
'fillColor' => '#00FF00',
'strokeColor' => 'red',
'draggable' => true,
'editable' => true,
]);
$map->addOverlay($rectangle);
$bikeLayer = new BicyclingLayer(['map' => $map->getName()]);
$map->appendScript($bikeLayer->getJs());
echo $map->display();
Totally untested
Throw the following error:
Setting unknown property: dosamigos\google\maps\LatLngBounds::0
@Pedro25 because you need to set the actual property:
$bounds = new LatLngBounds([
'northEast' => new LatLng(['lat' => -1.743391143288001, 'lng' => -79.98516381249999]),
'southWest' => new LatLng(['lat' => -1.1672520205625432, 'lng' => -76.98516381249999]),
]);
Please, review how the objects get instantiated... Unfortunately I cannot right now "debug" nor "test" even the code I write as sample. Apologies.
Greetings from Venezuela and thank you very much for the collaboration.
Saludos y fuerza @Pedro25
Provide the correct way to display a RECTANGLES on the map using the extension yii2-google-maps-library, I can not find any reference on the web.
I can not associate php arrays with their relative in javascript.
Please, I need examples to guide me.