Hi Yii!! i’m using JavaScript for show a Google Map with markers, but this works just for 1 marker:
[color="#008000"][size="2"]"actionMap"[/size][/color][size="2"] in [/size][color="#00bfff"][size="2"]"ProjectsController.php"[/size][/color]
public function actionMap($id)
{
$model=$this->loadModel($id);
$this->render('map',array(
'model'=>$model,
));
}
[color="#00bfff"]"map.php"[/color]
<?php
$this->breadcrumbs=array(
'Projects',
);
?>
<script
src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false">
</script>
<script>
var map;
var position;
function initialize()
{
if("<?php echo $model->lat; ?>"){
position = new google.maps.LatLng("<?php echo $model->lat; ?>", "<?php echo $model->lng; ?>");
} else {
position = new google.maps.LatLng(51.508742,-0.120850);
}
var mapProp = {
center:position,
zoom:3,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("googleMap"),mapProp);
marker = new google.maps.Marker({
position: position,
map: map
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<div id="googleMap" style="width:1000px;height:400px;"></div>
<div style="clear: both;"> </div>
And it works well!
But what i really want is to show all the projects markers, the problem is iterate the “[size=“2”]$model = new Projects(‘search’);[/size][size=“2”]” in the javascript for creating the markers, so i tried this[/size][size=“2”]:[/size]
[color="#008000"][size="2"]"actionMap"[/size][/color][size="2"] in [/size][color="#00bfff"][size="2"]"ProjectsController.php"[/size][/color]
public function actionMap()
{
$model = new Projects('search');
$this->render('map',array(
'model'=>$model,
));
}
[size="2"][color="#00BFFF"]"map.php"[/color][/size]
<?php
$this->breadcrumbs=array(
'Projects',
);
$count=count($model);
?>
<script>
src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false">
</script>
<script>
var map;
var position;
function initialize()
{
position = new google.maps.LatLng(51.508742,-0.120850);
var mapProp = {
center:position,
zoom:3,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("googleMap"),mapProp);
var length = "<?php echo $count; ?>";
for (var i = 0; i < length; i++) {
"<?php
$project = $model[$count];
$count--;
?>"
position = new google.maps.LatLng("<?php echo $project->lat; ?>", "<?php echo $project->lng; ?>");
marker = new google.maps.Marker({
position: position,
map: map
});
}
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<div id="googleMap" style="width:1000px;height:400px;"></div>
<div style="clear: both;"> </div>
But doesn’t work, as expected. How can i solve it?
Thank´s!