在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):marcferna/CakePHP-GoogleMapHelper开源软件地址(OpenSource Url):https://github.com/marcferna/CakePHP-GoogleMapHelper开源编程语言(OpenSource Language):PHP 99.4%开源软件介绍(OpenSource Introduction):Google Maps for CakePHP 2.xHelper for CakePHP framework that integrates a Google Map in your view using Google Maps API V3. CakePHP3You can find a working version for CakePHP 3 in the branch ##Demo See all the examples live here Installation
public $helpers = array('GoogleMap'); //Adding the helper
<?= $this->Html->script('http://maps.google.com/maps/api/js?sensor=true', false); ?> Note that the API key is not required but it you may want to add it if you want to monitor your usage or to buy additional usage quota. To add the api key: <?= $this->Html->script('http://maps.google.com/maps/api/js?key=YOUR_API_KEY&sensor=true', false); ?> UsagePrint the map to your view <?= $this->GoogleMap->map(); ?> Map OptionsBelow are the options available to set to your map:
In order modify any of the default options shown above you need to create your map passing the array as follows: <?
// Override any of the following default options to customize your map
$map_options = array(
'id' => 'map_canvas',
'width' => '800px',
'height' => '800px',
'style' => '',
'zoom' => 7,
'type' => 'HYBRID',
'custom' => null,
'localize' => true,
'latitude' => 40.69847032728747,
'longitude' => -1.9514422416687,
'address' => '1 Infinite Loop, Cupertino',
'marker' => true,
'markerTitle' => 'This is my position',
'markerIcon' => 'http://google-maps-icons.googlecode.com/files/home.png',
'markerShadow' => 'http://google-maps-icons.googlecode.com/files/shadow.png',
'infoWindow' => true,
'windowText' => 'My Position',
'draggableMarker' => false
);
?>
<?= $this->GoogleMap->map($map_options); ?> MarkersTo add a marker use: <?= $this->GoogleMap->addMarker($map_id, $marker_id, $position); ?> Where:
Example with address (using geolocation) <?= $this->GoogleMap->addMarker("map_canvas", 1, "1 Infinite Loop, Cupertino, California"); ?> Example with latitude and longitude <?= $this->GoogleMap->addMarker("map_canvas", 1, array('latitude' => 40.69847, 'longitude' => -73.9514)); ?> Marker OptionsThere are some marker options available to customize the marker popup info window:
In order modify any of the default options shown above you need to create your marker passing the array as follows: <?
// Override any of the following default options to customize your marker
$marker_options = array(
'showWindow' => true,
'windowText' => 'Marker',
'markerTitle' => 'Title',
'markerIcon' => 'http://labs.google.com/ridefinder/images/mm_20_purple.png',
'markerShadow' => 'http://labs.google.com/ridefinder/images/mm_20_purpleshadow.png',
'draggableMarker' => true
);
?>
<?= $this->GoogleMap->addMarker("map_canvas", 1, "1 Infinite Loop, Cupertino, California", $marker_options); ?> Draggable MarkerTo access the draggable marker's coordinates include an element in the html with the id of the marker. If a draggable marker with id of 1 is added, the coordinates can be accessed like: <input type="text" id="latitude_1" />
<input type="text" id="longitude_1" /> DirectionsTo add a route between two points use: <?= $this->GoogleMap->getDirections($map_id, $id, $position); ?> Where:
Example: <?= $this->GoogleMap->getDirections("map_canvas", "directions1", array("from" => "Lake Tahoe", "to" => "San Francisco")); ?> Directions OptionsThere are some directions options available to customize:
In order modify any of the default options shown above you need pass the array as follows: <?
// Override any of the following default options to customize your route
$directions_options = array(
'travelMode' => "WALKING",
'directionsDiv' => 'directions',
);
?>
<div id="directions"></div>
<?= $this->GoogleMap->getDirections("map_canvas", "directions1", array("from" => "Lake Tahoe", "to" => "San Francisco"), $directions_options); ?> PolylinesTo draw a line between to points use: <?= $this->GoogleMap->addPolyline($map_id, $id, $position); ?> Where:
Example: <?= $this->GoogleMap->addPolyline("map_canvas", "polyline", array("start" => array("latitude" =>37.772323 ,"longitude"=> -122.214897), "end" => array("latitude" =>21.291982 ,"longitude"=> -157.821856))); ?> Polylines OptionsThere are some drawing options available to customize:
In order modify any of the default options shown above you need to create your polyline passing the array as follows: <?
// Override any of the following default options to customize your polyline
$options = array(
"strokeColor" => "#FFFFFF",
"strokeOpacity" => 1,
"strokeWeight" => 8
);
?>
<?= $this->GoogleMap->addPolyline("map_canvas", "polyline", array("start" => array("latitude" => 37.772323 ,"longitude" => -122.214897), "end" => array("latitude" => 21.291982 , "longitude" => -157.821856)), $options); ?> CirclesTo draw a circle around a point use: <?= $this->GoogleMap->addCircle($map_id, $id, $center, $radius=100); ?> Where:
Example: <?= $this->GoogleMap->addCircle("map_canvas", "circle1", array('latitude' => 40.70894620592961, 'longitude' => -73.93882513046293)); ?> Circle OptionsThere are some drawing options available to customize:
In order modify any of the default options shown above you need to create your circle passing the array as follows: <?
// Override any of the following default options to customize your circle
$options = array(
"strokeColor" => "#FFFFFF",
"strokeOpacity" => 1,
"strokeWeight" => 5,
"fillColor" => "#E2252D",
"fillOpacity" => 0.3
);
?>
<?= $this->GoogleMap->addCircle("map_canvas", "circle1", array('latitude' => 40.70894620592961, 'longitude' => -73.93882513046293), 1000, $options); ?> |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论