1

I have this 'live map' which displays players online on my game server. I've added a 2 second timer which is supposed to update the markers position, but it doesn't work at all. What am I doing wrong?

The JavaScript:

<div id="map-canvas"></div>
var p_pos = <?php echo (empty($json_pos)) ? "" : $json_pos ?>;
var mapType = new SanMapType(0, 1, function (zoom, x, y) {
    return x == -1 && y == -1 
    ? "images/tiles/map.outer.png" 
    : "images/tiles/map." + zoom + "." + x + "." + y + ".png";//Where the tiles are located
});

var satType = new SanMapType(0, 3, function (zoom, x, y) {
    return x == -1 && y == -1 
    ? null 
    : "images/tiles/sat." + zoom + "." + x + "." + y + ".png";//Where the tiles are located
});

var map = SanMap.createMap(document.getElementById('map-canvas'), 
    {'Map': mapType, 'Satellite': satType}, 2, SanMap.getLatLngFromPos(0,0), false, 'Satellite');
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(document.getElementById('map-legend'));
if(p_pos !== "")
{
    for (var i = 0; i < Object.keys(p_pos).length; i++) 
    {
        console.log(p_pos[i].online);
        if(p_pos[i].online == 1) createMarker(i); 
    }
}   
google.maps.event.addListener(map, 'click', function(event) {
    var pos = SanMap.getPosFromLatLng(event.latLng);
    console.log(pos.x + "," + pos.y);
});                         
function createMarker(id)
{
    var p_windows = new google.maps.InfoWindow({
        content: "<p>"+p_pos[id].name+" <b>(ID: "+id+")</b><br>Ping: "+p_pos[id].ping+"<br>X: "+p_pos[id].x+"<br>Y: "+p_pos[id].y+"</p>"
    });
    var p_marker = new google.maps.Marker({
        position: SanMap.getLatLngFromPos(p_pos[id].x, p_pos[id].y),
        map: map,
        icon: "https://wiki.sa-mp.com/wroot/images2/8/81/Icon_0.gif"
    });
    google.maps.event.addListener(p_marker, 'click', function() {
        p_windows.open(map,p_marker);
    });
}

The timer:

<script>
$(function () {
    setTimeout(function () { $('#map-canvas').load(initialize); }, 1000);
})
</script>
duncan
  • 31,401
  • 13
  • 78
  • 99
AdamW24
  • 11
  • 1
  • 1
    the jQuery `load` function is meant to take a URL for an AJAX request. You're passing it what I assume is a variable, `initialize`, but there's no reference to it anywhere else in your question. It would also make life much easier if you posted the client-side version of your javascript, not the PHP you're using to create it, which makes no difference for what you're asking about. – duncan Jan 23 '16 at 09:46
  • I'm using http://forum.sa-mp.com/showthread.php?t=504181 which uses the Google Maps API. The client side javascript file is pretty big, not sure if I should post it here. – AdamW24 Jan 23 '16 at 12:42
  • What I mean is it doesn't help at all to see server-side code like `var p_pos = ;`... what would be useful is to see what that becomes when rendered client-side, e.g. `var p_pos = 'foobar';` – duncan Jan 23 '16 at 15:19
  • All it renders is a map and markers. The file fetches a .json file from another server, and then places them on the map. Not really anything else is done. – AdamW24 Jan 24 '16 at 14:27
  • I found this [thread](http://stackoverflow.com/questions/14771422/google-map-v3-auto-refresh-markers-only) that could possibly help. – gerardnimo Jan 26 '16 at 05:30

0 Answers0