Google 地图标记窗口

发布于 2024-12-13 15:30:41 字数 5777 浏览 2 评论 0原文

我正在尝试在我的 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;

        //]]>

I'm trying to add a link in my Google Map marker window. But my code only shows the marker and the window but it does not show the link.

I'm trying to add the link in this line:

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

when the link is clicked it go to some function of my index controller.
but why the link is not appearing in the window.

controller:

                   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);
} 


}

Model:

 public function ll($id = '')
    {

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

    }
          }

The generated html from my code(the map part only):

        <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;

        //]]>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

往昔成烟 2024-12-20 15:30:41

问题出在这一行:

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

InfoWindow 的内容是包含实际 HTML 代码的字符串。在您的情况下, 块将被忽略,正如您在生成的 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>";

The issue is with this line:

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

The content for an InfoWindow is a string containing the actual HTML code. In your case, the <?php block is ignored as you can see in the generated HTML:

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

It has to be :

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

Try this:

<?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>";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文