Dynamic google maps
I have to read data from a database and show it as markers on google map.I have done that but i am stucked because my map only displays the last marker from the table.I think the problem is on my javascript var locations array.I have a problem on how to parse data to google map's javascript locations array.Please help me.Here is my source code.
<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>
<%@page import="cgs.seismicEvents.DBConnection.DBUtility"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="javaQuery.j2ee.*"%>
<%@ page import="javaQuery.importClass.javaQueryBundle"%>
<%@ page import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>GeoLocation</title>
<%!
Connection con = null;
ResultSet rs = null;
Statement stmt = null;
//GeoLocation $gl;
//String ipaddress = null;
float event_Size;
double latitude;
double longitude;
Timestamp event_date;
%>
<%
String query="SELECT EVENTSIZE,LATITUDE,LONGITUDE,EVENTDATE FROM EVENTS where EVENTDATE>=currentdate-30 order by EVENT_DATE desc";
con = DBUtility.getConnection();
try {
stmt=con.createStatement();
} catch (SQLException e1) {
request.getSession().invalidate();
e1.printStackTrace();
}
try {
rs = stmt.executeQuery(query);
} catch (SQLException e) {
request.getSession().invalidate();
e.printStackTrace();
}
%>
<%
while(rs.next())
{
latitude = rs.getDouble("LATITUDE");
longitude =rs.getDouble("LONGITUDE");
eventSize=rs.getFloat("EVENTSIZE");
eventdate=rs.getTimestamp("EVENTDATE");
System.out.println("var locations = new google.maps.LatLng("+event_Size+","+latitude+","+longitude+","+event_date+");\n");
}
%>
<div id="map" style="width: 1400px; height: 900px;"></div>
<script type="text/javascript">
<%--My problem is here,I want to get values from the resultset and parse them to this array--%>
var locations =[
["<%=event_Size%>","<%=latitude%>","<%=longitude %>","<%=event_date%>]
];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: new google.maps.LatLng(-25.731340,28.218370),
mapTypeId: google.maps.MapTypeId.HYBRID
});
var infowindow = new google.maps.InfoWindow();
var marker;
var i;
for (i = 0; i < locations.length; i++){
// var data=locations[i];
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1],locations[i][2]),
icon:{
path: google.maps.SymbolPath.CIRCLE,
scale: 4
},
map: map
});
document.write();
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function(){
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
};
})(marker, i));
}
View Answers
Related Tutorials/Questions & Answers:
Dynamic google mapsDynamic google maps I have to read data from a database and show it as markers on
google map.I have done that but i am stucked because my map only... var locations array.I have a problem on how to parse data to
google map's
Dynamic google mapsDynamic google maps I have to read data from a database and show it as markers on
google map.I have done that but i am stucked because my map only... var locations array.I have a problem on how to parse data to
google map's
Advertisements
Dynamic google mapsDynamic google maps I have to read data from a database and show it as markers on
google map.I have done that but i am stucked because my map only... var locations array.I have a problem on how to parse data to
google map's
Dynamic google mapsDynamic google maps I have to read data from a database and show it as markers on
google map.I have done that but i am stucked because my map only... var locations array.I have a problem on how to parse data to
google map's
Dynamic google mapsDynamic google maps I have to read data from a database and show it as markers on
google map.I have done that but i am stucked because my map only... var locations array.I have a problem on how to parse data to
google map's
Google Zeitgeist-Trends-maps mashup
Google Zeitgeist-Trends-
maps mashup
A usable mashup of
google trends and zeitgeist most popular on
google maps to
show _where_ what is most popular
Read full Description ADS
Google maps GPS tracking enabled on
Google maps.
Recently released GE 4 Beta (December 16) has a compatible... if a person has GPS on his mobile, he will find the
accuracy of
Google Maps... in locating the current location of a device or
a person.
Google Maps does
Interactive Maps on particular area is done it should zoom in ie. how it happens in
google maps. I want zoom...Interactive Maps Hi.......................
How can u make
maps interactive using java code. I mean if a map of some location is stored in database
Google Web Toolkit
Google Web Toolkit
Google Web Toolkit (GWT) is a Java software development
framework that makes writing AJAX applications like
Google Maps and Gmail easy
for developers who don't
dynamic reportdynamic report i need complete code for generating
dynamic report in jsp
dynamic polymorphismdynamic polymorphism Develop with suitable hierarchy, classes for Point, Shape, Rectangle, Square, Circle,
Ellipse, Triangle, Polygon, etc. Design a simple test application to demonstrate
dynamic polymorphism
ModuleNotFoundError: No module named 'maps'ModuleNotFoundError: No module named '
maps' Hi,
My Python program is throwing following error:
ModuleNotFoundError: No module named '
maps'
How to remove the ModuleNotFoundError: No module named '
maps' error
ModuleNotFoundError: No module named 'maps'ModuleNotFoundError: No module named '
maps' Hi,
My Python program is throwing following error:
ModuleNotFoundError: No module named '
maps'
How to remove the ModuleNotFoundError: No module named '
maps' error
ModuleNotFoundError: No module named 'maps'ModuleNotFoundError: No module named '
maps' Hi,
My Python program is throwing following error:
ModuleNotFoundError: No module named '
maps'
How to remove the ModuleNotFoundError: No module named '
maps' error