json - Google Maps Refresh Markers -
i want refresh markers. used setinterval function. how delete markers? @ time markers added old markers ... thats not intended.
so code:
<!doctype html> <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <style type="text/css"> html { height: 100% } body { height: 100%; margin: 0; padding: 0 } #map_canvas { height: 100% } </style> <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=xyz&sensor=true"> </script> <script type="text/javascript"> var map; function initialize() { var mapoptions = { center: new google.maps.latlng(48.137, 11.577), zoom: 14, maptypeid: google.maps.maptypeid.roadmap }; map = new google.maps.map(document.getelementbyid("map_canvas"), mapoptions); } </script> <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script> </head> <body onload="initialize()"> <div id="map_canvas" style="width:100%; height:100%"></div> <script type="text/javascript"> setinterval(function() { $(document).ready(function() { $.getjson('./url.php', function(data) { var cars = data.rec.vehicles.vehicles; $.each(cars, function(key, data) { var latlng = new google.maps.latlng(data.position.latitude, data.position.longitude); var imageh = data.model; var bild = "/" + imageh + ".png"; if(data.fuelstate <=25) {bild="/empty.png";} var bild1= "/" + imageh + "1.png"; var tanken1=""; if(data.fuelstate<=25){tanken1="tanken";} console.log(bild); var contentstring ='<h1>'+data.model+" "+data.carname+'</h1><img border="0" align="center" src="' + data.model + '1.png"><br><br>kennzeichen: '+ data.licenseplate +'<br>fahrgestellnummer: '+data.vin+'<br>fuellstand: ' + data.fuelstate + '% <img border="0" align="absmiddle" src="' + data.fuelstate + '.png"><br>zustand: <img border="0" align="absmiddle" src="' + data.innercleanliness + '.png"><br>adresse: ' +data.address+'<br><a href="https://de.drive-now.com/php/metropolis/vehicle_details?vin='+ data.vin +'">dieses fahrzeug jetzt buchen!</a><br><br>'+tanken1; var infowindow = new google.maps.infowindow({ content: contentstring }); var marker = new google.maps.marker({ position: latlng, title: data.model, icon: bild }); google.maps.event.addlistener(marker, 'click', function() { infowindow.open(map,marker); google.maps.event.addlistener(map, 'click', function() {if(infowindow){infowindow.close();}}); }); marker.setmap(map); }); }); }); clearmarkers(); }, 10000); $(document).ready(function() { $.getjson('./petrolstations.txt', function(data) { $.each(data, function(key, data) { var latlng = new google.maps.latlng(data.lat, data.lng); var bild1 = "/petrol.png"; var contentstring1 = data.name; var infowindow = new google.maps.infowindow({ content: contentstring1 }); var marker = new google.maps.marker({ position: latlng, title: data.lng, icon: bild1 }); google.maps.event.addlistener(marker, 'click', function() { infowindow.open(map,marker); google.maps.event.addlistener(map, 'click', function() {if(infowindow){infowindow.close();}}); }); marker.setmap(map); }); }); }); </script> </body> </html>
thanks :))
keep references markers have been created (in array).
to remove them, iterate through array calling .setmap(null) on each marker.
Comments
Post a Comment