|
|
@ -6,6 +6,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var gotfirstfix = false;
|
|
|
|
var gotfirstfix = false;
|
|
|
|
|
|
|
|
var lastMapUpdateTimestamp = 0;
|
|
|
|
|
|
|
|
|
|
|
|
var playerPosition = {
|
|
|
|
var playerPosition = {
|
|
|
|
coords: {
|
|
|
|
coords: {
|
|
|
@ -29,15 +30,31 @@ if (gamemaptype == "leaflet") {
|
|
|
|
var map = mapboxMap();
|
|
|
|
var map = mapboxMap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Make sure map places are refreshed even when location isn't
|
|
|
|
|
|
|
|
var mapRefreshInterval = setInterval(function () {
|
|
|
|
|
|
|
|
if (gotfirstfix) {
|
|
|
|
|
|
|
|
var currentTimestamp = Math.floor(Date.now() / 1000);
|
|
|
|
|
|
|
|
if (lastMapUpdateTimestamp < (currentTimestamp - 10)) {
|
|
|
|
|
|
|
|
updatePlaceLayer(playerPosition.coords.latitude, playerPosition.coords.longitude);
|
|
|
|
|
|
|
|
lastMapUpdateTimestamp = currentTimestamp;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, 30 * 1000);
|
|
|
|
|
|
|
|
|
|
|
|
watchLocation(function (position) {
|
|
|
|
watchLocation(function (position) {
|
|
|
|
|
|
|
|
playerPosition = position;
|
|
|
|
if (gotfirstfix) {
|
|
|
|
if (gotfirstfix) {
|
|
|
|
setMapLocation(position.coords.latitude, position.coords.longitude);
|
|
|
|
setMapLocation(position.coords.latitude, position.coords.longitude);
|
|
|
|
updatePlaceLayer(position.coords.latitude, position.coords.longitude);
|
|
|
|
// Don't refresh map at an interval less than ten seconds
|
|
|
|
|
|
|
|
var currentTimestamp = Math.floor(Date.now() / 1000);
|
|
|
|
|
|
|
|
if (lastMapUpdateTimestamp < (currentTimestamp - 10)) {
|
|
|
|
|
|
|
|
updatePlaceLayer(position.coords.latitude, position.coords.longitude);
|
|
|
|
|
|
|
|
lastMapUpdateTimestamp = currentTimestamp;
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
animateMapIn(position.coords.latitude, position.coords.longitude, 16, position.coords.heading);
|
|
|
|
animateMapIn(position.coords.latitude, position.coords.longitude, 16, position.coords.heading);
|
|
|
|
gotfirstfix = true;
|
|
|
|
gotfirstfix = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
playerPosition = position;
|
|
|
|
|
|
|
|
}, function (error) {
|
|
|
|
}, function (error) {
|
|
|
|
geoerrorcount++;
|
|
|
|
geoerrorcount++;
|
|
|
|
console.log("Geolocation error #" + geoerrorcount + ": ", error);
|
|
|
|
console.log("Geolocation error #" + geoerrorcount + ": ", error);
|
|
|
@ -65,7 +82,7 @@ function updatePlaceLayer(latitude, longitude) {
|
|
|
|
callAPI("nearbyplaces", {
|
|
|
|
callAPI("nearbyplaces", {
|
|
|
|
latitude: latitude,
|
|
|
|
latitude: latitude,
|
|
|
|
longitude: longitude,
|
|
|
|
longitude: longitude,
|
|
|
|
radius: 1
|
|
|
|
radius: 2
|
|
|
|
}, function (data) {
|
|
|
|
}, function (data) {
|
|
|
|
map.updatePlaceLayer(data);
|
|
|
|
map.updatePlaceLayer(data);
|
|
|
|
});
|
|
|
|
});
|
|
|
|