【问题标题】:Google Map marker window谷歌地图标记窗口
【发布时间】:2011-12-21 19:31:56
【问题描述】:

我正在尝试在我的 Google 地图标记窗口中添加一个链接。但是我的代码只显示了标记和窗口,但没有显示链接。

我正在尝试在这一行中添加链接:

$marker['infowindow_content'] = "<?php echo anchor('index/get_by_id/$id',{$row->subject} on {$row->address}')?>";

当点击链接时,它会转到我的索引控制器的某些功能。 但是为什么链接没有出现在窗口中。

控制器:

                   function index()
{


    if(empty($_POST)){
    $this->load->helper('form');
    $this->googlemaps->initialize();
    $marker = array();
    //$this->main_model->get_map();

    if($result = $this->main_model->ll()){
        //var_dump($result);
        foreach($result->result() as $row) {
            //var_dump($row);
            //$data[]=$row;
             $marker['position'] = "{$row->lat},{$row->lng}";
             $id=$row->id;
             $marker['infowindow_content'] = "<?php echo anchor('index/get_by_id/$id',{$row->subject} on {$row->address}')?>";

             $marker['animation'] = 'DROP';
             //var_dump($marker['position ']);
             $this->googlemaps->add_marker($marker);
        }
    }


    //$this->googlemaps->add_marker($marker);
    $data['map'] = $this->googlemaps->create_map();
    $data['list'] = $this->main_model->getdata();
    $this->load->view('main_view',$data);
} 


}

型号:

 public function ll($id = '')
    {

    $sql = $this->db->get('info');
    if ($sql->num_rows () >0) {
        return $sql;
    }
    else{
        return null;

    }
          }

从我的代码生成的 html(仅地图部分):

        <script type="text/javascript">
        //<![CDATA[

        var map; // Global declaration of the map
        var iw = new google.maps.InfoWindow(); // Global declaration of the infowindow
        var lat_longs = new Array();
        var markers = new Array();
        function initialize() {

            var myLatlng = new google.maps.LatLng(65.84815, 24.14670);
            var myOptions = {
                zoom: 15,
                center: myLatlng,
                mapTypeId: google.maps.MapTypeId.ROADMAP}
            map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

        var myLatlng = new google.maps.LatLng(65.85051,24.14529);

        var markerOptions = {
            position: myLatlng, 
            map: map,
            animation:  google.maps.Animation.DROP      
        };
        marker_0 = createMarker(markerOptions);

        marker_0.set("content", "<?php echo anchor('index/get_by_id/1',street problem on something home)?>");

        google.maps.event.addListener(marker_0, "click", function() {
            iw.setContent(this.get("content"));
            iw.open(map, this);

        });

        var myLatlng = new google.maps.LatLng(65.84931,24.14555);

        var markerOptions = {
            position: myLatlng, 
            map: map,
            animation:  google.maps.Animation.DROP      
        };
        marker_1 = createMarker(markerOptions);

        marker_1.set("content", "<?php echo anchor('index/get_by_id/2',hello on 11 some)?>");

        google.maps.event.addListener(marker_1, "click", function() {
            iw.setContent(this.get("content"));
            iw.open(map, this);

        });

        var myLatlng = new google.maps.LatLng(65.84858,24.14160);

        var markerOptions = {
            position: myLatlng, 
            map: map,
            animation:  google.maps.Animation.DROP      
        };
        marker_2 = createMarker(markerOptions);

        marker_2.set("content", "<?php echo anchor('index/get_by_id/3',problem street on 78900 street)?>");

        google.maps.event.addListener(marker_2, "click", function() {
            iw.setContent(this.get("content"));
            iw.open(map, this);

        });

        var myLatlng = new google.maps.LatLng(65.85000,24.14773);

        var markerOptions = {
            position: myLatlng, 
            map: map,
            animation:  google.maps.Animation.DROP      
        };
        marker_3 = createMarker(markerOptions);

        marker_3.set("content", "<?php echo anchor('index/get_by_id/4',gulshan street on 11 gulshan)?>");

        google.maps.event.addListener(marker_3, "click", function() {
            iw.setContent(this.get("content"));
            iw.open(map, this);

        });

        var myLatlng = new google.maps.LatLng(65.84620,24.14593);

        var markerOptions = {
            position: myLatlng, 
            map: map,
            animation:  google.maps.Animation.DROP      
        };
        marker_4 = createMarker(markerOptions);

        marker_4.set("content", "<?php echo anchor('index/get_by_id/5',broken road on banani)?>");

        google.maps.event.addListener(marker_4, "click", function() {
            iw.setContent(this.get("content"));
            iw.open(map, this);

        });

        var myLatlng = new google.maps.LatLng(65.84961,24.15164);

        var markerOptions = {
            position: myLatlng, 
            map: map,
            animation:  google.maps.Animation.DROP      
        };
        marker_5 = createMarker(markerOptions);

        marker_5.set("content", "<?php echo anchor('index/get_by_id/6',no lamp on arbritary)?>");

        google.maps.event.addListener(marker_5, "click", function() {
            iw.setContent(this.get("content"));
            iw.open(map, this);

        });


        }


    function createMarker(markerOptions) {
        var marker = new google.maps.Marker(markerOptions);
        markers.push(marker);
        lat_longs.push(marker.getPosition());
        return marker;
    }

        window.onload = initialize;

        //]]>

【问题讨论】:

  • 我们需要查看更多代码...例如,您如何处理“infowindow_content”?
  • 'infowindow_content' 接受你想在标记窗口中显示的字符串值。如果你写“hi”,标记窗口显示你好。我想将 hi 添加为可点击的链接,而不是简单的“hi”。
  • @martan 您可以将 html 代码输入信息窗口。也许是&lt;a href="somewhere.com"&gt;hi&lt;/a&gt;。你也在用zend框架吗?
  • @kjy112.i 正在使用 codeigniter 框架,我也尝试过使用 html 代码..但在这种情况下,当我点击链接时,我会一直回到同一页面而不是去另一个页面。
  • @martan 你能从你的输出中发布生成的 html 吗?

标签: php codeigniter google-maps google-maps-markers


【解决方案1】:

问题在于这一行:

$marker['infowindow_content'] = "<?php echo anchor('index/get_by_id/$id',{$row->subject} on {$row->address}')?>";

InfoWindow 的内容是一个包含实际 HTML 代码的字符串。在您的情况下,&lt;?php 块被忽略,您可以在生成的 HTML 中看到:

marker_0.set("content", "<?php echo anchor('index/get_by_id/1',street problem on something home)?>");

必须是:

marker_0.set("content", "<a href='index/get_by_id/1'>street problem on something home</a>");

试试这个:

<?php
    $subject = $row->subject;
    $address = $row_>address;
?>

var index = '<?php echo $id; ?>';
var subject = '<?php echo $subject; ?>';
var address = '<?php echo $address; ?>';

$marker['infowindow_content'] = "<a href='index/get_by_id/" + index + "'>" + subject + " on " + address + "</a>";

【讨论】:

    猜你喜欢
    • 2011-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多