Using the Google Places Details API, I have included a Google API with a callback function called initMap in the src attribute. Here is the code snippet:
<div class="tab-pane active" id="timeline">
<p class="lead">Location</p>
<hr>
<div class="row">
<div class="col-md-1"></div>
<div class="col-md-8">
<h2><a href="#"></a>
<span>location <b style="color:black;"> kolkata</b></span></h2>
<p></p>
<div id="map" style="width:100%;height:400px;"></div>
<script src="https://maps.googleapis.com/maps/api/js?key=API_KEY&libraries=places&callback=initMap"></script>
<p></p>
</div>
</div>
</div>
I also created the initMap function within the same HTML document:
<script>
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 22.652687, lng: 88.376882},
zoom: 15
});
var infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
service.getDetails({
placeId: 'ChIJvYbRT7Gd-DkR6QZQfJP9ZJg'
}, function(place, status) {
debugger
if (status === google.maps.places.PlacesServiceStatus.OK) {
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent('<div><strong>' + place.name + '</strong><br>' +
'Place ID: ' + place.place_id + '<br>' +
place.formatted_address + '</div>');
infowindow.open(map, this);
});
}
});
}
</script>
This setup works perfectly when the function is inside a script tag. But how can I call initMap from a controller?