Solved

Whats wrong with my JSP?

Posted on 2010-08-24
8
619 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
Comment Utility
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
Comment Utility
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
Comment Utility
<%Longitude;%>
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
Comment Utility

('<%=Latitude%>','<%=Longitude%>');  
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 20

Expert Comment

by:Sathish David Kumar N
Comment Utility
Sorry chaituu: i didnt see ur code
0
 

Author Comment

by:bhession
Comment Utility
Sorry guys that didnt seem to work either
0
 
LVL 11

Assisted Solution

by:Manish
Manish earned 250 total points
Comment Utility
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
Comment Utility
I thought this was closed off, my apologies. The above lead to the solution.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to implement Singleton Design Pattern in Java.
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now