Mysql 是否可以立即刷新谷歌地图?
我可以从MySQL表中提取这些信息,并显示我需要的内容,但我希望获得一些关于如何使用当前代码每隔5秒左右刷新这些数据的帮助 没有太多的数据可以显示,就像任何给定时间的5或8个标记一样。我已经包括了我当前用来提取数据的代码。我对PHP/MySQL还行,但对谷歌地图很陌生。 我尝试添加代码以刷新谷歌地图Mysql 是否可以立即刷新谷歌地图?,mysql,google-maps,refresh,Mysql,Google Maps,Refresh,我可以从MySQL表中提取这些信息,并显示我需要的内容,但我希望获得一些关于如何使用当前代码每隔5秒左右刷新这些数据的帮助 没有太多的数据可以显示,就像任何给定时间的5或8个标记一样。我已经包括了我当前用来提取数据的代码。我对PHP/MySQL还行,但对谷歌地图很陌生。 我尝试添加代码以刷新谷歌地图 setInterval(function() { $.ajax({ url: '/localhost/my/site.php', data: {action: 'test'}, type: '
setInterval(function() {
$.ajax({ url: '/localhost/my/site.php',
data: {action: 'test'},
type: 'post',
success: function(output) {
alert('hi');
// change the DOM with your new output info
}
});
}, 5000);
但还是不行,我的代码怎么了?
当mysql数据库更新时,是否可以从mysql获取新数据
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js? sensor=true" /></script>
<script type='text/javascript'>
//This javascript will load when the page loads.
jQuery(document).ready( function($){
setInterval(function() {
$.ajax({ url: '/localhost/my/site.php',
data: {action: 'test'},
type: 'post',
success: function(output) {
alert('hi');
// change the DOM with your new output info
}
});
}, 5000);
//Initialize the Google Maps
var geocoder;
var map;
var markersArray = [];
var infos = [];
geocoder = new google.maps.Geocoder();
var myOptions = {
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
//Load the Map into the map_canvas div
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
//Initialize a variable that the auto-size the map to whatever you are plotting
var bounds = new google.maps.LatLngBounds();
//Initialize the encoded string
var encodedString;
//Initialize the array that will hold the contents of the split string
var stringArray = [];
//Get the value of the encoded string from the hidden input
encodedString = document.getElementById("encodedString").value;
//Split the encoded string into an array the separates each location
stringArray = encodedString.split("****");
var x;
for (x = 0; x < stringArray.length; x = x + 1)
{
var addressDetails = [];
var marker;
//Separate each field
addressDetails = stringArray[x].split("&&&");
//Load the lat, long data
var lat = new google.maps.LatLng(addressDetails[1], addressDetails[2]);
var image = new google.maps.MarkerImage(addressDetails[3]);
//Create a new marker and info window
var marker = new google.maps.Marker({
map: map,
icon: image,
position: lat,
content: addressDetails[0]
});
//Pushing the markers into an array so that it's easier to manage them
markersArray.push(marker);
google.maps.event.addListener( marker, 'click', function () {
closeInfos();
var info = new google.maps.InfoWindow({content: this.content});
//On click the map will load the info window
info.open(map,this);
infos[0]=info;
});
//Extends the boundaries of the map to include this new location
bounds.extend(lat);
}
//Takes all the lat, longs in the bounds variable and autosizes the map
map.fitBounds(bounds);
//Manages the info windows
function closeInfos(){
if(infos.length > 0){
infos[0].set("marker",null);
infos[0].close();
infos.length = 0;
}
}
});
</script>
</head>
<body>
<div id='input'>
<?php
//Initialize your first couple variables
$encodedString = ""; //This is the string that will hold all your location data
$x = 0; //This is a trigger to keep the string tidy
//Now we do a simple query to the database
// DB INFO CONNECTION IS HERE AND WORKS
$result = mysql_query("SELECT * FROM `ulocation` WHERE `ul_lat`!='' AND `ul_long`!=''
AND `ul_onduty`='1'",$db1);
//Multiple rows are returned
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
//This is to keep an empty first or last line from forming, when the string is
split
if ( $x == 0 )
{
$separator = "";
}
else
{
//Each row in the database is separated in the string by four *'s
$separator = "****";
}
$status='0';
$cadd = sql::getval('cal_address', 'call', "WHERE `cal_id`='$row[14]'");
$num = sql::getval('cal_num', 'call', "WHERE `cal_id`='$row[14]'");
$pcond = sql::getval('cal_pcond', 'call', "WHERE `cal_id`='$row[14]'");
$list="$num $cadd";
//Saving to the String, each variable is separated by three &'s
$encodedString = $encodedString.$separator."<table border=0 width='350' height='20'
class='maincolm' cellpadding=0 cellspacing=0><td align=left valign=top><h2></h2></td>
<tr><td width=100%><font size=3 face=arial><p><b>".$row[2].
"</b>".
"<br>Address: $list".
"<br>Call Type: $pcond".
"<br><br>Lat: ".$row[5].
"<br>Long: ".$row[6].
"</td></table>".
"</p>&&&".$row[5]."&&&".$row[6]."&&&".$row[8]."&&&".$row[14];
$x = $x + 1;
}
?>
<input type="hidden" id="encodedString" name="encodedString" value="<?php echo
$encodedString; ?>" />
<? echo "<body oncontextmenu=\"return false\" style=\"overflow: hidden; \"
topmargin=0 leftmargin=0 rightmargin=0 bottommargin=0>";
<div id=\"map_canvas\"></div>
</body>
</html>";
?>
//此javascript将在页面加载时加载。
jQuery(文档).ready(函数($){
setInterval(函数(){
$.ajax({url:'/localhost/my/site.php',
数据:{action:'test'},
键入:“post”,
成功:功能(输出){
警报(“hi”);
//使用新的输出信息更改DOM
}
});
}, 5000);
//初始化谷歌地图
var地理编码器;
var映射;
var-markersArray=[];
var-infos=[];
geocoder=新的google.maps.geocoder();
变量myOptions={
缩放:8,
mapTypeId:google.maps.mapTypeId.ROADMAP
}
//将地图加载到Map_canvas div中
var map=new google.maps.map(document.getElementById(“map_canvas”),myOptions);
map=new google.maps.map(document.getElementById(“map_canvas”),myOptions);
//初始化一个变量,该变量将自动调整地图的大小,使其与正在打印的内容一致
var bounds=new google.maps.LatLngBounds();
//初始化编码字符串
var编码环;
//初始化将保存拆分字符串内容的数组
var stringArray=[];
//从隐藏输入中获取编码字符串的值
encodedString=document.getElementById(“encodedString”).value;
//将编码字符串拆分为一个数组,并分隔每个位置
stringArray=encodedString.split(“****”);
var x;
对于(x=0;x0){
infos[0]。设置(“标记”,空);
infos[0]。关闭();
infos.length=0;
}
}
});
根据这里的链接
我的结论是建议使用轮询,它使数据库每X秒调用一次来更新标记信息
另外,有一篇文章提到在mysql中使用触发器,你也可以看看
考虑到mysql不需要通知
作为对你的目的的建议。如果您想从marker(例如marker onclick事件)中刷新数据,则可以从中进行db调用以刷新标记。这就是我在marker onclick上做这件事的方式
希望对您有所帮助您能给我一些关于如何使用轮询的示例吗?轮询使数据库每X秒调用一次,以更新标记信息和标记颜色。对于标记信息,可以使用onclick事件,但对于标记选项(例如:颜色),当特定的表更新时,标记颜色将从绿色变为红色。redI将尝试此方式进行轮询。在你的代码中加入一个计时器,它会使db调用每X秒或每分钟检索每个标记的数据。同样,在java中,你需要将这些标记存储在数组中,相应地更新标记的选项。我已经修改了我的帖子并添加了我的代码,你有什么建议吗?如果有任何帮助,我们将不胜感激