2009-11-25 57 views
0

我正在使用谷歌地圖,我試圖從我的數據庫(訪問)傳遞一個值到我的JavaScript代碼。將值從JSP傳遞到Javascript

var centerPoint = new GLatLng(<% Double.parseDouble(myclass.getLatitude()); %> , <% Double.parseDouble(myclass.getLongitude()); %>); 

其中myclass.getLatitude()返回我的緯度的字符串表示,我將其轉換爲加倍等等

但問題是地圖上沒有顯示。

回答

3

使用Double.parseDouble()毫無意義,因爲它會立即轉換回String。但你的問題是你沒有打印座標(<%包裝java scriptlet; <%=輸出表達式評估的結果)。這應該這樣做:

var centerPoint = new GLatLng(<%= myclass.getLatitude() %> , <%= myclass.getLongitude() %>);