I'm trying to add a Google Map to a jquery.mobile site javascript and the Google Maps API. The problem is that every time I load the map, most of the map is greyed out. I've done some research and apparently I must add the command:
google.maps.event.trigger(map, 'resize');
But I've been fiddling with this for the last few hours and I can't seem to make it work. This is the code I'm using:
var myLatlng = new google.maps.LatLng(34.310774,66.225586);
var mapOptions = {
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
// boundry
var southWest = new google.maps.LatLng(31.207164,61.347656);
var northEast = new google.maps.LatLng(37.617713,69.785156);
var bounds = new google.maps.LatLngBounds(southWest,northEast);
map.fitBounds(bounds);
google.maps.event.trigger(map, 'resize');
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…