Javascript 标记坐标不正确
我正在创建一个名为ArmA 3的游戏的管理员/用户控制面板,使用名为“放逐”的mod。“放逐”在数据库中放置X、Y(Z)坐标。我正在使用PHP获取这些坐标,并使用flipal.js在播放器所在的位置放置一个标记。我使用的是自定义图像(15360x15360) 问题: 假设我在位置(63407801)(x,y)。标记将远离我实际所在的位置(参见下面的图) (ingame位置) (单张标记) PHP代码+传单.js:Javascript 标记坐标不正确,javascript,php,html,leaflet,coordinates,Javascript,Php,Html,Leaflet,Coordinates,我正在创建一个名为ArmA 3的游戏的管理员/用户控制面板,使用名为“放逐”的mod。“放逐”在数据库中放置X、Y(Z)坐标。我正在使用PHP获取这些坐标,并使用flipal.js在播放器所在的位置放置一个标记。我使用的是自定义图像(15360x15360) 问题: 假设我在位置(63407801)(x,y)。标记将远离我实际所在的位置(参见下面的图) (ingame位置) (单张标记) PHP代码+传单.js: <?php require_once "application.php"
<?php
require_once "application.php";
?>
<html lang="en">
<head>
<title>Search</title>
<link rel="stylesheet" href="leaflet.css">
<meta charset="UTF-8">
</head>
<body>
<?php
if(isset($_GET["q"])) {
$uid = $_GET["q"];
$UCP = new UCP("localhost", "root", "root", "testdb", "3306");
$r = $UCP->getPlayer($uid);
if($r) {
$coords = $UCP->getPlayerCoords($uid);
}
}
?>
<div id="map" style="height: 100%"></div>
<script src="js/leaflet.js"></script>
<script>
var mapMinZoom = 0;
var mapMaxZoom = 4;
var map = L.map('map', {
minZoom: mapMinZoom,
maxZoom: mapMaxZoom,
center: [15360, 15360],
crs: L.CRS.Simple
});
var w = 15360,
h = 15360,
url = 'http://localhost/images/Chernarus_Isles_nogrid.png';
var southWest = map.unproject([0, h], mapMaxZoom);
var northEast = map.unproject([w, 0], mapMaxZoom);
var bounds = new L.LatLngBounds(southWest, northEast);
map.fitBounds(bounds);
L.imageOverlay(url, bounds).addTo(map);
<?php
if(isset($_GET["q"])) {
if($r) { ?>
var pos_x_player = Math.round(<?php echo $coords["pos_x"]; ?>);
var pos_y_player = Math.round(<?php echo $coords["pos_y"]; ?>);
var p_loc = map.unproject([pos_y_player, pos_x_player], mapMaxZoom);
L.marker(p_loc).addTo(map).bindPopup('Player Location');
<?php
}
}
?>
</script>
搜寻
var-mapMinZoom=0;
var mapMaxZoom=4;
var map=L.map('map'{
minZoom:mapMinZoom,
maxZoom:mapMaxZoom,
中间:[1536015360],
crs:L.crs.Simple
});
var w=15360,
h=15360,
url='1〕http://localhost/images/Chernarus_Isles_nogrid.png';
var soutwest=map.unproject([0,h],mapMaxZoom);
var northEast=map.unproject([w,0],mapMaxZoom);
var bounds=新的L.LatLngBounds(西南、东北);
映射边界(bounds);
L.imageOverlay(url,bounds).addTo(map);
var pos_x_player=Math.round();
var pos_y_player=Math.round();
var p_loc=map.unproject([pos_y_player,pos_x_player],mapMaxZoom);
L.marker(p_loc).addTo(map).bindpoop('Player Location');
它成功地连接到数据库并获取坐标,但传单总是远离我实际所在的位置
任何帮助都将不胜感激。如果我遗漏了什么,请告诉我:)欢迎来到SO
传单地图的第一个参数是一个对象,它按顺序获取坐标[水平,垂直]
:
需要一个[x,y]
因此,标记的错误位置很可能是因为您以错误的顺序传递了坐标:
map.unproject([pos_y_player, pos_x_player], mapMaxZoom)
…应该是:
map.unproject([pos_x_player, pos_y_player], mapMaxZoom)
点对象是以像素为单位测量的,因此,是的,在这种情况下,源图像和您的图像必须相同,才能在不进行修改的情况下获得精确的坐标。一旦确定了大小差异,就可以使用函数将原始坐标转换为地图坐标。嘿,谢谢!回复:我尝试过改变变量,但仍然有很大差距。事实上,我已经不在地图上了:可能是图像的大小吗?可能是。没有你的形象,我帮不了你。