I am writing an application to get latitude, longitude of a position in a google map using java and javascript.
The below code part gives an error:
code(It's a part of a jsp file):
<script type="text/javascript">
var map;
//Initialization & some more code goes here
function centerChanged() {
<%
int lat=0,lng=0;
lat=%>map.getCenter().lat();<%
lng=%>map.getCenter().lng();<%
//request.setAttribute("lat", lat);
//request.setAttribute("lng", lng);
%>
}
From the above code, these are the two lines that cause the error:
lat=%>map.getCenter().lat();<%
lng=%>map.getCenter().lng();<%
Additional Information:
map.getCenter().lat()
<< This will return a Number as mentioned in google maps API:
This is the error I am getting:
org.apache.jasper.JasperException: PWC6033: Error in Javac compilation for JSP
PWC6197: An error occurred at line: 81 in the jsp file: /maptest.jsp PWC6199: Generated servlet error: string:///maptest_jsp.java:127: incompatible types found : void required: int
PWC6197: An error occurred at line: 82 in the jsp file: /maptest.jsp PWC6199: Generated servlet error: string:///maptest_jsp.java:130: incompatible types found : void required: int
Can anyone please tell what is wrong?
lat
andlng
Java variables or JavaScript variables? – Joachim Sauerlat
andlng
are supposed to be Java/JSP variables andmap.getCenter().lat();
is JavaScript code then, the posted code can not work: JavaScript is executed one the client and after the JSP code is executed on the server. So you can't assign a JS value to a Java/JSP variable this way. – Joachim Sauermap.getCenter().lat()
value to a java variable(int lat
), should I declaremap
as a java variable(not a javascript variable)? Can that be a solution? – Dilini