How to display json 'playercoordinates' and display the marker's of all other users in Google map

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)

Thanks everyone, I find out a way to do this
// Write the jsonResponse to a file as below:

// Create a new FileWriter object to following path
FileWriter fileWriter = new FileWriter(“c:\Work\Project\WebContent\data.json”);

//Writting the jsonObject into sample.json
fileWriter.write(jsonObject.toJSONString());
fileWriter.close();

an then in javascript, I called getJSON function as below to achieve the markers in google map

  >   $.getJSON("data.json", function(json1) {
      $.each(json1, function(key, data) {
        // call Google Map here 
      });
    });
2 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.