I have a JS that I send coordinates from that into a Servlet.
In my JS I get coordinates from a jsp page like this:
function main1() {
$.ajax({
url: 'ServeltConnection',
type: "GET",
dataType: "json",
data: {
latitude: pos.lat,
longitude: pos.lng,
},
success: function(data){
//call of functions
}
});
}
I need these coordinates so as to send them into my servlet for getting a return into a json format.
In my Servlet:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("application/json");
PrintWriter out = new PrintWriter(response.getWriter(), true);
List<Shop> shops;
try{
//code for connection with database
shops=getShops(request.getParameter("latitude"),request.getParameter("longitude"));
String json = new Gson().toJson(shops);
response.getWriter().write(shops);
db.close();
} catch (Exception ex) {
out.println("Exception: " + ex.getMessage());
When I give specific coordinates in latitude and longitude I GET my json right, but when I' m trying to get coordinates from the js it's not working. I think that the wrong is the way I parse longitude and latitude from js..I searched for parsing JSON but I can't do it. Can you help me?