I am using googleMaps API javascript, some time it works well but some time I reload the page then I got an exception in console tap of browsers and the map doesn't show.
Uncaught nc js?key=MyAPIKey&callback=initMap:98 my javascript Code:
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=NyAPIKey&callback=initMap">
</script>
function initMap() {
if (typeof google === 'object' && typeof google.maps === 'object') {
// Create the map.
var map = new google.maps.Map(document.getElementById('googleapi'), {
zoom: 14,
center: { lat: @Model.SelectedAppliance.Lat, lng: @Model.SelectedAppliance.Lon },
mapTypeId: 'terrain'
});
var marker = new google.maps.Marker({
position: map.center,
map: map,
title: 'Device Home'
});
// Construct the circle for each value in citymap.
// Note: We scale the area of the circle based on the population.
var positionCircle = new google.maps.Circle({
strokeColor: '#FF0000',
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: '#FF0000',
fillOpacity: 0.35,
map: map,
center: map.center,
radius: getMeters(@Model.SelectedAppliance.TriggerMile),
});
return positionCircle;
} else {
window.location.reload(true);
}
}
function ContainPoint(device, lat, lon) {
if (typeof google === 'object' && typeof google.maps === 'object') {
markerCPosition = new google.maps.LatLng(lat, lon);
var circleBounds = initMap().getBounds();
if (!circleBounds.contains(markerCPosition)) {
$(device).hide(true);
}
} else {
window.location.reload(true);
}
}