【发布时间】:2018-10-06 16:21:53
【问题描述】:
我在我的 codeigniter 网站上显示地图时遇到问题。我正在使用 googlemaps.php 库,我的控制器和视图如下所示:
控制器:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Maps extends My_Controller {
public function __construct(){
parent::__construct();
$this->load->model('Maps');
}
public function maps(){
$this->load->library('googlemaps');
$mapmarkers = $this->Maps->find(); //From here get lan. lat.
foreach($mapmarkers as $m){
$marker = array();
$marker['position'] = $m['location'];
$content = "My Information";
$marker['infowindow_content'] = $content ;
$this->googlemaps->add_marker($marker);
}
$data['map'] = $this->googlemaps->create_map();
//var_dump($data);
$this->load_theme('maps', $data);
}
}
查看:
<div class="map-content content-area container-fluid">
<div class="col-lg-12">
<div class="row">
<?php echo $map['js']; ?>
<?php echo $map['html']; ?>
</div>
</div>
结果是一个空白页,但是当我转储变量map 时,它显示了正确的数据。
我的控制台也没有任何错误。
var_dump 日志:
array(1) { ["map"]=> array(3) { ["js"]=> string(1439) " " ["html"]=> string(61) "
" ["markers"]=> array(1) { ["marker_0"]=> array(2) { ["latitude"]=>
string(17) "48.28866326125372" ["longitude"]=> string(17)
"16.37960056416341" } } } }
谁能告诉我我的代码有什么问题,或者我该如何解决它
【问题讨论】:
-
你需要用一些基本配置来初始化地图
$this->googlemaps->initialize($config);。希望这会有所帮助! -
请访问此链接解决您的问题:Stackoverflow。希望对你有帮助!!!
标签: php codeigniter google-maps-api-3