【问题标题】:googlemaps codeigniter does not show in the viewgooglemaps codeigniter 未显示在视图中
【发布时间】: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-&gt;googlemaps-&gt;initialize($config);。希望这会有所帮助!
  • 请访问此链接解决您的问题:Stackoverflow。希望对你有帮助!!!

标签: php codeigniter google-maps-api-3


【解决方案1】:

你不是 initialize 库,更新你的函数如下

public function maps(){
    $this->load->library('googlemaps');
    $this->googlemaps->initialize();

    $mapmarkers = $this->Maps->find(); //From here get lan. lat. 
    foreach($mapmarkers as $m){
        $marker = array();
        $marker['position'] = $m['location'];
        $marker['infowindow_content'] = 'My Information';
        $this->googlemaps->add_marker($marker);
    }

    $data['map'] = $this->googlemaps->create_map();
    //var_dump($data);
    $this->load_theme('maps', $data);
}

HTML

<head>
<?=$map['js'];?>
</head>

<body>
<?=$map['html'];?>
</body>

【讨论】:

  • 同样的问题...没有任何改变
  • load_theme 函数中有什么 .?/
  • 模板路径
  • 在模板内调用 print_r($map)l 检查是否将数据设置为变量
猜你喜欢
  • 1970-01-01
  • 2014-01-18
  • 1970-01-01
  • 1970-01-01
  • 2015-10-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多