我想要这个功能到我的项目中。
我正在尝试提供功能,单击 Onbutton,我从 MySQL 中获取坐标数据到一个数组中,然后将此数组放入文本框的值中,以便 JavaScript 读取此值。但是,当我将 var 坐标值放入折线时,它显示为空白,当我从文本框中复制相同的值并将其粘贴到相同的 var 时,它的工作。
Java代码:
try {
Connection.getConnection();
java.sql.PreparedStatement preparedStatement = Connection.con
.prepareStatement("select * from co_ordinates_data");
resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
latitude.add(resultSet.getDouble("latitude"));
longitude.add(resultSet.getDouble("longitude"));
latlong.add("new google.maps.LatLng("
+ resultSet.getDouble("latitude") + ","
+ resultSet.getDouble("longitude") + ")");
}
size = latitude.size();
} catch (Exception e) {
System.out.println("path exception " + e.toString());
}
return "execute";
//textbox
<input type="text" id="latlng" value="<s:property value="latlong"/>"
here is my js code:
function initialize() {
var myLatLng = new google.maps.LatLng(28.493729, 77.09255);
var mapOptions = {
zoom : 8,
center : myLatLng,
mapTypeId : google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map-canvas"),
mapOptions);
var cordinates = document.getElementById("latlng").value;
var flightPlanCoordinates = [cordinates ];
var flightPath = new google.maps.Polyline({
path : flightPlanCoordinates,
strokeColor : "#FF0000",
strokeOpacity : 1.0,
strokeWeight : 2
});
flightPath.setMap(map);
}