0

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

5
  • can you add some good samples of data for both $locations and $services? Commented Mar 25, 2020 at 7:03
  • Assuming that the data for both locations and services comes initially from a database and assuming that these things are related by a common key you ought to create a single variable with these items already linked... hard to be specific when nobody knows the data structure or content Commented Mar 25, 2020 at 7:29
  • I have uploaded sample data, inn first part Commented Mar 25, 2020 at 8:35
  • not really good enough.. which variable is that? What is the other variable content? How do they relate to one another? If you are not prepared to add the relevant data then I cannot help Commented Mar 25, 2020 at 8:40
  • I have an idea now, i dont know wether it have logic, inoreder to searching inside map, can i search outside the map with php database and pass it to map Commented Mar 25, 2020 at 9:43

0