我正在尝试在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;
//]]>
答案 0 :(得分:0)
问题在于这一行:
$marker['infowindow_content'] = "<?php echo anchor('index/get_by_id/$id',{$row->subject} on {$row->address}')?>";
InfoWindow的内容是一个包含实际HTML代码的字符串。在您的情况下,您可以在生成的HTML中看到<?php
块被忽略:
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>";