2011-07-28 127 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());