Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript][HTML]Odświeżanie markerów google maps
olszam
post 18.06.2014, 19:04:16
Post #1





Grupa: Zarejestrowani
Postów: 342
Pomógł: 23
Dołączył: 20.01.2011
Skąd: Chełm

Ostrzeżenie: (0%)
-----


Mam zwykły skrypcik na losowe markery w mapce, ale niestety nie mogę sobie poradzić z odświeżaniem markerów co daną sekundę. Próbowałem z setInterval odświeżyć punkty, ale zamiast odświeżyć to dodawały kolejne markery, z setMap też próbowałem ale nie wychodzi mi.

Kod jaki mam na ten czas:
  1. html, body, #map {
  2. height: 100%;
  3. margin: 0px;
  4. padding: 0px
  5. }
  6. </style>
  7. <script src="http://maps.google.com/maps/api/js?v=3.exp" type="text/javascript"></script>
  8.  
  9. </head>
  10. <div id="map"></div>
  11.  
  12. <script type="text/javascript">
  13.  
  14. var map = new google.maps.Map(document.getElementById('map'), {
  15. zoom: 3,
  16. center: new google.maps.LatLng(0, 0),
  17. mapTypeId: google.maps.MapTypeId.ROADMAP
  18. });
  19.  
  20. var infowindow = new google.maps.InfoWindow();
  21. var marker , i;
  22.  
  23. var locations = [
  24. ['random5', Math.floor((Math.random() * 100) + 1), Math.floor((Math.random() * 100) + 1), 5],
  25. ['random4', Math.floor((Math.random() * 100) + 1), Math.floor((Math.random() * 100) + 1), 4],
  26. ['random3', Math.floor((Math.random() * 100) + 1), Math.floor((Math.random() * 100) + 1), 3],
  27. ['random2', Math.floor((Math.random() * 100) + 1), Math.floor((Math.random() * 100) + 1), 2],
  28. ['random1', Math.floor((Math.random() * 100) + 1), Math.floor((Math.random() * 100) + 1), 1]
  29. ];
  30.  
  31. for (i = 0; i < locations.length; i++) {
  32. marker = new google.maps.Marker({
  33. position: new google.maps.LatLng(locations[i][1], locations[i][2]),
  34. map: map
  35. });
  36.  
  37. google.maps.event.addListener(marker, 'click', (function(marker, i) {
  38. return function() {
  39. infowindow.setContent(locations[i][0]);
  40. infowindow.open(map, marker);
  41. }
  42. })(marker, i));
  43. }
  44. </script>
  45. </body>
  46. </html>
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 18.07.2025 - 04:25