我使用的是Google地圖API,並且想動態地創建標記。我正在使用Zend Framework,這是我的代碼的一部分。從PHP控制器動態添加標記
誰可以幫助我獲取此對象以獲取標記,然後在地圖上顯示它們?
<script>
function initMap() {
var locations[];
var image = 'https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png';
var map = new google.maps.Map(document.getElementById('ressearch'), {
zoom: 15,
center: {lat: 36.8454481, lng: 10.1995665}
});
var markers = <?php echo json_encode($all_users_loc); ?>;
//console.info(markers);
// Create an array of alphabetical characters used to label the markers.
var labels = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
for(var i=0;i<2;i++){
location[i]=markers
}
var locations = [
{lat: <?=$this->translate($all_users_loc[0][co_latitude])?>, lng: <?=$this->translate($all_users_loc[0][co_longitude])?>},
{lat: 36.84573142925444, lng: 10.19872965563718},
{lat: 36.84630667456557, lng: 10.199920556439793}
]
// Add some markers to the map.
// Note: The code uses the JavaScript Array.prototype.map() method to
// create an array of markers based on a given "locations" array.
// The map() method here has nothing to do with the Google Maps API.
var markers = locations.map(function(location, i) {
return new google.maps.Marker({
position: location,
label: labels[i % labels.length],
icon: image,
animation: google.maps.Animation.DROP,
});
});
// Add a marker clusterer to manage the markers.
var markerCluster = new MarkerClusterer(map, markers,
{imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'});
}
google.maps.event.addDomListener(window, "load", initMap);
</script>
<?php echo json_encode($all_users_loc); ?>
<?=$this->translate($all_users_loc[0][co_latitude])?>
<div id="ressearch"></div>
//this is the result
[{"co_adresse":"adresse 1","co_longitude":"10.19959870","co_latitude":"36.84540516"},{"co_adresse":"adresse","co_longitude":"33.58555244","co_latitude":"10.33333330"}] 36.84540516
標記位置是否需要在不加載頁面進行更新? –
@RamkumarP我想動態製作標記時加載頁面 –