I have been trying to generate a map with Latitude & Longitude ,I am fetching these lat & lon from MYSQL DB. I have a java class which will connect to database & retrieve lat,lon ,So i need to pass these values to a JavaScript which has a code to generate map.
In the Javascript i have a function called addmarker() Which has lat & lon.The Actual Requirement is I have to pass lat,lon form the java class to Javascript.
Here is my java code:
Connection conn = null;
PreparedStatement pst = null;
ResultSet rs = null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "db5";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "root";
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url + dbName, userName, password);
pst = conn.prepareStatement("select latitude,longitude from nidgis where nidevid=?");
pst.setString(1, n);
rs = pst.executeQuery();
while(rs.next())
{
rs.getInt("latitude");
rs.getInt("longitude");
}
}
catch (Exception e)
{
System.out.println(e);
}
Here is my JS code:
<script>
function addMarker()
{
var vehicle = new MQA.Poi({
lat: vehicle_lat,
lng: vehicle_lng,
});
var icon = new MQA.Icon(
'https://cdn2.iconfinder.com/data/icons/gpsmapicons /blue/gpsmapicons07.png',
35, 42);
vehicle.setIcon(icon);
vehicle.setKey("abc");
map.addShape(vehicle);
vehicle.setRolloverContent("Vehicle # KA05 9999");
}
MQA.EventUtil.observe(window, 'load', function() {
/*Create an object for options*/
var options={
elt:document.getElementById('map'), /*ID of element on the page where you want the map added*/
zoom:10, /*initial zoom level of map*/
latLng:{lat:39.743943, lng:-105.020089}, /*center of map in latitude/longitude*/
mtype:'map' /*map type (map)*/
};
/*Construct an instance of MQA.TileMap with the options object*/
window.map = new MQA.TileMap(options);
MQA.withModule('geocoder', function() {
/*Executes a geocode and adds result to the map*/
map.geocodeAndAddLocations("Denver CO");
});
});
</script>
<body>
<div id='map' style='width:1560px; height:730px;'></div>
<button id="getBasicSample" onclick="addMarker();">show veh1</button>
</body>