On click on some button I am calling this javasript function locateMe(labels, newimages) and later calls an makeAjaxCall(currentLatitude, currentLongitude, temLabel, plyrEmail) ajax
function. This ajax calls the servlet ‘PlayerLocation’ and save the user_id, name, latitude and longitude into database
function locateMe(labels, newimages) {
newcords = getLocation();
for (i=0; i< labels.length; i++ ){
var temLabel = labels[i].innerText;
plyrImages = newimages[0].src ;userMarker[i] = new google.maps.Marker({ position : { lat : currentLatitude, lng : currentLongitude}, zoom : 9, icon : 'images/pointer1.PNG', title : temLabel, draggable : true, map : map }); markers.push(userMarker[i]); makeAjaxCall(currentLatitude, currentLongitude, temLabel, plyrEmail);
}
}
'makeAjaxCall (), ajax fucntion
function makeAjaxCall (currentLatitude, currentLongitude, temLabel, plyrEmail) {
$.ajax({
type: “POST”,
url: “PlayerLocation”,
data: {currentLat: currentLatitude, currentLong: currentLongitude, title: temLabel, email: plyrEmail},
success: function(data){
alert(currentLatitude +", " + currentLongitude + ", " + temLabel + ", " + plyrEmail);}
});
}
In the ‘PlayerLocation’ servlet response i am sending back the ‘playercoordinates’ list which has the list of all users from database with their user_id, latitude and longitude
> List<PlayerCoordinates> playercoordinates = SoccerUtils.getPlayercoordinates();
String jsonResponse = new Gson().toJson(playercoordinates);
response.setContentType(“application/json”);
response.setCharacterEncoding(“UTF-8”);
response.getWriter().write(jsonResponse);
PrintWriter out=response.getWriter();//System.out.print(jsonResponse);
request.getSession().setAttribute(“playercoordinates”, playercoordinates);
RequestDispatcher rd = request
.getRequestDispatcher(“listplayers.jsp”);
rd.forward(request, response);
out.flush();
How do I display the json ‘playercoordinates’ and display the marker’s of all other users in Google map and call another function changeMarkerPosition(marker)