我正在使用带有 CakePHP 的GoogleMapsHelper在我的应用程序中包含 Google Map。
为了向我的地图添加标记,文档说我应该使用以下语法,其中三个变量是地图 ID、标记 ID 和标记位置。
<?= $this->GoogleMap->addMarker("map_canvas", 1, array('latitude' => 40.69847, 'longitude' => -73.9514)); ?>
考虑到这一点,我一直在尝试遍历我的数据库并显示我的所有观点,但它没有做任何事情:这是代码,每个帖子都有 (lat) 和 (lng)。
<?php
foreach ($posts as $post): ?>
<?php $this->GoogleMap->addMarker("map_canvas", $post['Post']['id'], array('latitude' => $post['Post']['lat'], 'latitude' => $post['Post']['lng'])); ?>
<?php endforeach; ?>
如何将这些条目作为标记加载到我的地图中?提前致谢!