function initialiseLocations() { $.get("/api/customers/" + customerId + "/get-locations", { id: $("#id").val(), internal_id: $("#internal-id").val(), name: $("#name").val() }, function(response) { if(!response.success) return false; if(!response.locations) return false; let map = maps["map"]; let bounds = new google.maps.LatLngBounds; for(let i in response.locations) { let location = response.locations[i]; let position = { lat: location.latitude, lng: location.longitude }; let options = { map: map, position: position, title: location.name } if(location.icon) { options.icon = "/img/markers/" + location.icon; } bounds.extend(position); let marker = new google.maps.Marker(options); marker.locationId = location.id; marker.addListener("click", function() { window.open("/account/locations/" + this.locationId, "_blank"); }); } map.fitBounds(bounds); }); }