Google map infowindow is not looping from php data

2020-05-04 19:49发布

In my Laravel project, I am taking latitudes and longitudes values from Mysql database and displaying it as a marker in google maps, to show one clinic location, One clinic may or may not have multiple locations. It is working perfectly, but the issue is that the clinic in each location will offer different services.

When I click on each location marker I, have to show multiple service name which each clinic is offering as infowindow

When I consoled am getting the things as below

{servicename: "Service A", locid: 53, locname: "Ventura Systems Pvt Ltd"}
{servicename: "Service B", locid: 53, locname: "Ventura Systems Pvt Ltd"}

But on my google map marker, only last service name is showing.

Following is the code of google maps

<script>
var locations = <?php echo $locations ?>;
var services =<?php echo json_encode($services);?>;
console.log(services);

function initMap() {
    var locations = <?php echo $locations ?>;

    var j;
    for (j = 0; j < locations.length; j++) { 
    var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 8,
    center: {lat: parseFloat(locations[j]['locationLat']), lng:parseFloat(locations[j]['locationLong'])}
  });
    setMarkers(map);
  }
}
function setMarkers(map) {
var locations = <?php echo $locations ?>;
var services = <?php echo $services ?>;



for (var i = 0; i < locations.length; i++) {


   var marker = new google.maps.Marker({
                map: map,
                position: {lat: parseFloat(locations[i]['locationLat']), lng:parseFloat(locations[i]['locationLong'])},
                map: map,
                title: locations[i]['locationName']
               });
    var infowindow = new google.maps.InfoWindow()

    var content = '<p><b>#Client_Company#</b><br>'+
                        '#Client_Address#<br>'+
                        '#Client_City#,&nbsp; #Client_State# &nbsp; #Client_Zip#<br>'+
                        '<a href="member_detail.cfm?ID=#Client_ID#">View Details</a>';

    google.maps.event.addListener(marker,'click', (function(marker,content,infowindow){ 
    return function() {
        infowindow.setContent(content);
        infowindow.open(map,marker);
    };
})(marker, content,infowindow));  

  }

}
</script>
<script async defer src="https://maps.googleapis.com/maps/api/js?key=MY_API_KEY&callback=initMap">
 </script>

Can you please help me to show multiple service name in each location, with respect to their locations

0条回答
登录 后发表回答