im new socket.io and only through with vanilla js, so this is confusing me a little. I'm currently working on a socket.io multiplayer game. When a player go to the webpage, a question is generated asking the user to guess where a particular city is. The webpage is basically the world map. To guess where the place is, all players have to do is click on a particular place on the map.
//CLIENT SIDE
// This event listener will call addMarker() when the map is clicked.
google.maps.event.addListener(map, 'click', function(event) {
addMarker(event.latLng);
socket.emit('marker', {'lat': markers[0].position.k, 'long': markers[0].position.D});
socket.emit('show-marker', addMarker);
});
}
//CLIENT SIDE
// Add a marker to the map and push to the array.
function addMarker(location) {
clearMarkers();
markers = [];
var marker = new google.maps.Marker({
position: location,
map: map
});
markers.push(marker);
console.log(location);
console.log("marker: " + markers[0].position.k + " " + markers[0].position.D);
}
//SERVER SIDE
socket.on('marker', function(data) {
console.log('marker latitude: ' + data.lat + ', marker longitude:' + data.long);
});
so far, i am able to console log the latitude and longitude position of when any of player clicks on the map (both on the client and server side). but im unable to grasp the concept of how to display the googlemaps marker to all the players on the webpage.
this is what my code looks like. any help is appreciated!
Aucun commentaire:
Enregistrer un commentaire