Solved

Whats wrong with my JSP?

Posted on 2010-08-24
8
623 Views
Last Modified: 2012-05-10
I am trying to use Google Maps Javascript API V3 with my JSP. Now the problem I am having is that

<%=Latitude%>,<%Longitude%> seems to cause an error im my JSP.

I want to create marker for each entry in the Vector, so as the for loop, loopsI want a create a marker on my map. How can I do this?

I have attached my JSP so far.

I dont know javascript so this is proving tricky.
0
Comment
Question by:bhession
8 Comments
 

Author Comment

by:bhession
ID: 33512444
Sorry here is the .jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><title>Test</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
  html { height: 100% }
  body { height: 100%; margin: 0px; padding: 0px }
  #map_canvas { height: 100% }
</style>
<script type="text/javascript"
    src="http://maps.google.com/maps/api/js?sensor=false">
</script>
<script type="text/javascript">
  function initialize() {
    var latlng = new google.maps.LatLng(53.3, 8.9);
    var myOptions = {
      zoom: 7,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);

  
  }

</script>
</head>
<body onload="initialize()">
<%@ page import="com.google.project.Turbine" %>
<%@ page import="java.util.Vector" %>

<%
Vector<Turbine> turbines = new Vector<Turbine>();
turbines=(Vector<Turbine>)request.getAttribute("turbines");


if (turbines.size()==0){
	System.out.println("No record found matching your search"+"\n");
}
else if(turbines.size()!=0)
	{
for (int i=0; i < turbines.size(); i++)
{
	Turbine turbine = (Turbine)turbines.elementAt(i);

int ID = turbine.getID();
String TurbineSerialNo  = turbine.getTurbineSerialNo();
String ModelNumber = turbine.getModelNumber();
String ControllerSerialNo = turbine.getControllerSerialNo();
String MobileNo = turbine.getMobileNo();
String IMEINo = turbine.getIMEINo();
String AlternatorBNo = turbine.getAlternatorBNo();
String AlternatorCNo = turbine.getAlternatorCNo();
int Owner = turbine.getOwner();
String Address1 = turbine.getAddress1();
String Address2 = turbine.getAddress2();
String Address3 = turbine.getAddress3();
String County = turbine.getCounty();
String Country = turbine.getCountry();
String Northings = turbine.getNorthings();
String Eastings = turbine.getEastings();

double Latitude = Double.parseDouble(Northings);
double Longitude = Double.parseDouble(Eastings);

/*
out.println("<h4><br><b>ID is </b>"+ID
	    +"<br><b>TurbineSerialNo: </b>"+TurbineSerialNo
	    +"<br><b>Model No: </b>"+ModelNumber
	    +"<br><b>Controller Serial No: </b>"+ControllerSerialNo
	    +"<br><b>Mobile No: </b>"+MobileNo
	    +"<br><b>IMEI No: </b>"+IMEINo
	    +"<br><b>Alternator B No: </b+>"+AlternatorBNo
	    +"<BR><B>Alternator C No: </B>"+AlternatorCNo
	    +"<BR><B>Owner: </B>"+Owner
	    +"<BR><B>Address: </B>"+Address1+","+Address2+","+Address3+","+County+","+Country
	    +"<BR><B>Latitude: </B>"+Northings
	    +"<BR><B>Longitude: </B>"+Eastings);*/
	    

}
out.println("</h4>");

}
%>


  <div id="map_canvas" style="width:100%; height:100%"></div>
  <script type="text/javascript">
  var latlng2 = new google.maps.LatLng(<%=Latitude%>,<%=Longitude%>);
  var marker = new google.maps.Marker({
        position: myLatlng2, 
        map: map,
        title:"Hello World!"
    });   

</script>
  


  </body>
</html>

Open in new window

0
 
LVL 20

Accepted Solution

by:
chaitu chaitu earned 250 total points
ID: 33512573
did u printed Latitude in scriplet whether value is coming or not??
try single quote

 var latlng2 = new google.maps.LatLng('<%=Latitude%>','<%=Longitude%>');
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 33512575
<%Longitude;%>
0
The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 33512601

('<%=Latitude%>','<%=Longitude%>');  
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 33512615
Sorry chaituu: i didnt see ur code
0
 

Author Comment

by:bhession
ID: 33518682
Sorry guys that didnt seem to work either
0
 
LVL 11

Assisted Solution

by:Manish
Manish earned 250 total points
ID: 33518889
This
var latlng2 = new google.maps.LatLng(<%=Latitude%>,<%=Longitude%>);
is outside of for loop. Put inside or make Latitude outside of for loop.
0
 

Author Closing Comment

by:bhession
ID: 34135007
I thought this was closed off, my apologies. The above lead to the solution.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ejb entity bean example 2 17
jQuery on Submit 4 45
ASP.NET Content Page 3 33
Disable selected option from one select box when selected in another select box 26 45
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question