我需要谷歌地图的帮助
我想要没有刷新地图更改标记
我从mysql获取数据并创建标记
我的档案:
function initialize(){
var latlng = new google.maps.LatLng(55.472627,23.15918);
var geocoder; var map; var markersArray = []; var infos = [];
var myOptions = { zoom:8, 中心:latlng, mapTypeId:google.maps.MapTypeId.ROADMAP };
var map = new google.maps.Map(document.getElementById(“map_canvas”),myOptions);
var encodedString; var stringArray = [];
encodedString = document.getElementById(“encodedString”)。value; stringArray = encodedString.split(“ * *”);
var x; for(x = 0; x< stringArray.length; x = x + 1){
var addressDetails = [];
addressDetails = stringArray [x] .split(“,”);
var lat = new google.maps.LatLng(addressDetails [0],addressDetails [1]); 的console.log(LAT);
console.log(addressDetails [0],addressDetails [1]);var marker = new google.maps.Marker({ map: map, position: lat, icon: addressDetails[2], title: "Atnaujinta: "+addressDetails[3]+"" }); } }setInterval('updateMap()', 10000); </script> </head> <?php //get data form mysql mysql_connect('localhost', 'adena_root', 'gintariukas1'); mysql_select_db('adena_nav'); $encodedString = ""; $x = 0; $mysql = mysql_query("SELECT X,Y,marker,data FROM nav"); while ($row = mysql_fetch_array($mysql, MYSQL_NUM)){ if ( $x == 0 ){ $separator = ""; }else{ $separator = "****"; } $encodedString = $encodedString.$separator. "".$row[0]. ",".$row[1]. ",".$row[2]. ",".$row[3]; $x = $x + 1; } ?> <body onload="initialize()"> <input type="hidden" id="encodedString" name="encodedString" value="<?php echo $encodedString; ?>" /> <div id="map_canvas"></div> </body> </html>
也许有人知道?:)
答案 0 :(得分:0)
您可以使用AJAX执行此操作。首先创建一个单独的页面,它将以JSON格式显示您的地图数据,然后在JavaScript中获取它们以将它们显示到地图中。这是一个很好的教程,虽然它使用谷歌地图v2,你可以简单地将它们更改为v3代码。