开发者

google maps API (map not displaying)

I'm confused. I'm working with Google Maps API for the first time (version V3) and I don't understand why the Jquery onready shorthand isn't working.

 <script type="text/javascript"
   src="http://maps.google.com/maps/api/js?sensor=set_to_true_or_false">
 </script>

 <script type="text/javascript">
    function initialize() {
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var myOptions = {
    zoom: 8,
    center: latlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
   var map = new google.maps.Map(document.getElementById("map"),
    myOptions);
 }

</script>   

I tried to both $(function(){ }); and $(document).ready(function(){});

My syntax was correct both times and firebug console showed no errors. Neither initializes the map. However, when I added

onload="initialize() to my body tag, it worked.

Just curious what is happening here.

EDIT: HERE IS THE ACTUAL CODE

   &开发者_如何学Pythonlt;script type="text/javascript"
      src="http://maps.google.com/maps/api/js?sensor=false">
</script>

 <script type="text/javascript">


  $(function(){
     function initialize() {
     var latlng = new google.maps.LatLng(-34.397, 150.644);
     var myOptions = {
     zoom: 8,
     center: latlng,
     mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map")
    ,
     myOptions); 
 }
   });


Sorry, this was fairly obvious.

I was defining initialize but not calling it.


Maybe your problem is <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=set_to_true_or_false"> Did you set it to true or false? BTW, did you link to a valid jQuery js sheet? Do you have a proper <Doctype>?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜