Reputation: 2781
Sometimes, the Google map does not load properly, and don't allow to insert a marker:
This is my code to create the map:
var companyCreateMap;
var companyCreateMapInitialZoom = 7;
function companyLoadInitialMap()
{
companyCreateGeocoder = new google.maps.Geocoder();
var companyCreateInitialLocation = new google.maps.LatLng(companyCreateMapInitialCenterLat, companyCreateMapInitialCenterLng);
var companyCreateMapOptions = {
center: companyCreateInitialLocation,
zoom: companyCreateMapInitialZoom,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
companyCreateMap = new google.maps.Map(document.getElementById(companyCreateMapCanvas), companyCreateMapOptions);
google.maps.event.addListener(companyCreateMap, 'click', updateMarkerCoordenatesOnClick);
companyCreateGetUserLocation();
}
function companyCreateGetUserLocation()
{
if (navigator.geolocation)
{
browserSupportFlag = true;
navigator.geolocation.getCurrentPosition(function (companyCreatePosition)
{
var companyCreateCenterLocation = new google.maps.LatLng(companyCreatePosition.coords.latitude, companyCreatePosition.coords.longitude);
companyCreateMap.setCenter(companyCreateCenterLocation);
companyCreateMap.setZoom(17);
companyCreateMarker = new google.maps.Marker({ position: companyCreateCenterLocation, map: companyCreateMap, animation: google.maps.Animation.DROP });
},
function (error)
{
// User did not accept to give location
//handleNoGeolocation(browserSupportFlag, error);
});
}
// Browser doesn't support Geolocation
else
{
browserSupportFlag = false;
//handleNoGeolocation(browserSupportFlag);
}
}
This does not happen every time, only from time to time, and I get no errors in the console.
Any idea?
Upvotes: 0
Views: 1031
Reputation: 22490
You need to trigger a map resize when the fade-in has completed.
$('#map-canvas').fadeIn(200, function() {
// Trigger a map resize
google.maps.event.trigger(map, 'resize');
});
Upvotes: 6