jquery移动地图标记mysql
好吧,我已经为此挣扎了将近一个星期了,不管我怎么努力,我似乎都无法让它工作 我已经成功地运行了一个计时器setInterval来从mysql表中检索值,这个文件名为apijson.php,并将它们返回到字符串及其fine。转到输出div 我在将它集成到GoogleMapAPI中时遇到了问题,无法将标记移动并平移到刚刚检索到的坐标 我希望我能理解我想要实现的目标jquery移动地图标记mysql,jquery,mysql,maps,Jquery,Mysql,Maps,好吧,我已经为此挣扎了将近一个星期了,不管我怎么努力,我似乎都无法让它工作 我已经成功地运行了一个计时器setInterval来从mysql表中检索值,这个文件名为apijson.php,并将它们返回到字符串及其fine。转到输出div 我在将它集成到GoogleMapAPI中时遇到了问题,无法将标记移动并平移到刚刚检索到的坐标 我希望我能理解我想要实现的目标 <html> <head> <style type="text/css"> ht
<html>
<head>
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map-canvas { height: 100% }
</style>
<script language="javascript" type="text/javascript" src="jquery.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script>
function initialize() {
var myLatlng = new google.maps.LatLng(55.953429,-3.188095);
var mapOptions = {
zoom: 11,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Marker'
});
moveBus( map, marker );
}
function moveBus( map, marker ) {
marker.setPosition( new google.maps.LatLng( 0, 0 ) );
map.panTo( new google.maps.LatLng( 0, 0 ) );
};
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"></div>
<div id="output"></div>
<script id="source" language="javascript" type="text/javascript">
setInterval(function()
{
$.ajax({
url: 'apijson.php', //the script to call to get data
data: "Driver=<?php echo $_GET['Driver']; ?>", //you can insert url argumnets here to pass to api.php for example "id=5&parent=6"
dataType: 'json', //data format
success: function(data) //on recieve of reply
{
var xx = data[7]; //latitude
var xy = data[8]; //longtude
var drv = data[2]; //driver
var clsn = data[1]; //id
marker.setPosition( new google.maps.LatLng( data[7], data[8] ) );
map.panTo( new google.maps.LatLng( data[7], data[8] ) );
$('#output').html("<b>Lat : </b>"+xx+"<b> Long : </b>"+xy+"<b> Driver : </b>"+drv+" ("+clsn+")"); //Set output element html
}
}, 5000);
});
</script>
</body>
</html>
在函数中设置本地变量,即标记,并在ajax成功事件中尝试访问该函数。如果它是全局的,比如window.myTestMarker=/*…*/;然后,您可以在成功事件中使用window.myTestMarker访问它,您应该更接近您想要的结果。真的很抱歉,我刚刚开始使用ajax/javascript。我该如何将其放入我的代码中,我尝试将我的所有变量更改为window.varname,现在我得到了一个空白页。我在拔头发。哈哈,非常感谢你的帮助。