2011-07-28 130 views
0

我有谷歌地图的JavaScript代码谷歌地图问题

 $(document).ready(function() { 

     var zoom = 16; // zoom level 
     var latitude = $('#latitude').text(); //latitude 
     var longitude = $('#longitude').text(); //longitude 
     var map_description = $('#map_description').text(); 





      if (GBrowserIsCompatible()) { // if the browser is compatible with Google Map's 
       var map = document.getElementById("myMap"); // Get div element 
       var m = new GMap2(map); // new instance of the GMap2 class and pass in our div location. 


       m.setCenter(new GLatLng(latitude, longitude), zoom); 


       m.openInfoWindow(m.getCenter(), map_description); // displays the text 
       m.setMapType(G_SATELLITE_MAP); // sets the default mode. G_NORMAL_MAP, G_HYBRID_MAP 

       var c = new GMapTypeControl(); // switch map modes 
       m.addControl(c); 

       m.addControl(new GLargeMapControl()); // creates the zoom feature 
      } 
      else { 
       alert("Upgrade your browser, man!"); 

      } 
     }); 

和问题是,我不能出的数据“放大”从JavaScript。我想在html文件中找到数据。我已经用它的经度,纬度来描述

var zoom = $('#zoom').text(); //zoom 

<div id='zoom'>16</div> 

并且这个不用动手。有人可以帮我解决这个问题吗?

+0

这似乎是一个很奇怪的事情,我可以问为什么? – ianbarker

回答

2

我认为你需要解析变焦整数值例如为:

var zoom=parseInt($('zoom').text());