I want this functionality to my project.
I am trying to provide the functionality, Onbutton click, I fetch the coordinates data from MySQL into an array and then put this array to the value of the text box, so that JavaScript read this value. But when I put the var coordinates value to polyline it shows blank and when I copy the same value from the textbox and pase it to the same var its working.
Java code:
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);
}