开发者

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&amp;v=2&amp;sensor=false&amp;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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜