Loading GMaps via ajax
I'm loading a page containing a GMaps using the aj开发者_运维问答ax()
method of jQuery.
The HTML page i'm loading is:
<script src="http://maps.google.com/maps?file=api&v=2&sensor=false&key=MY_API_KEY" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map_canvas"));
var geocoder = new GClientGeocoder();
geocoder.getLatLng("San Francisco, California",function(point) {
if (point) {
map.setCenter(point, 7);
}
});
map.setUIToDefault();
}
});
</script>
<div id="map_canvas"></div>
After retrieving this page, I'm setting its contents to a div using the html()
method. The map is not showed, while other pages containing scripts, loaded in the same way, are correctly shown.
Is this a specific issue about GMaps, that doesn't allow to be loaded via an ajax request?
Try using the google ajax loader code instead:
google ajax apis
If I remember correctly, the Google Maps API script will only work when included normally on the page; it will not work if it's added after the page is loaded, like you're doing.
精彩评论