CONNEXION
  • RetourJeux
    • Tests
    • Soluces
    • Previews
    • Sorties
    • Hit Parade
    • Les + attendus
    • Tous les Jeux
  • RetourActu
    • Culture Geek
    • Astuces
    • Réalité Virtuelle
    • Rétrogaming
    • Toutes les actus
  • RetourHigh-Tech
    • Actus JVTECH
    • Bons plans
    • Tutoriels
    • Tests produits High-Tech
    • Guides d'achat High-Tech
    • JVTECH
  • RetourVidéos
    • A la une
    • Gaming Live
    • Vidéos Tests
    • Vidéos Previews
    • Gameplay
    • Trailers
    • Chroniques
    • Replay Web TV
    • Toutes les vidéos
  • RetourForums
    • Hardware PC
    • PS5
    • Switch
    • Xbox Series
    • Overwatch 2
    • FUT 23
    • League of Legends
    • Genshin Impact
    • Tous les Forums
  • PC
  • PS5
  • Xbox Series
  • PS4
  • One
  • Switch
  • Wii U
  • iOS
  • Android
  • MMO
  • RPG
  • FPS
En ce moment Genshin Impact Valhalla Breath of the wild Animal Crossing GTA 5 Red dead 2
Etoile Abonnement RSS

Sujet : Need help Javascript

DébutPage précedente
1
Page suivantePage suivante
xRyadboudebouz7 xRyadboudebouz7
MP
Niveau 5
15 janvier 2017 à 16:51:04

Hello, quelqu'un pourrait m’expliquer ce bout de code? svp.

Ce code donne accès à une map google où sont positionnés des points bien précis.

<style type="text/css">
html, body { height: 100%; margin: 0; padding: 0; }
#map { height: 100%; }
</style>
</head>
<body>
<div id="map"></div>

<script type="text/javascript">

function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 50.85034, lng: 4.35171},
zoom: 12
});

var jours = ["dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"];
var locations = [];

$.getJSON("https:opendata.bruxelles.be/api/records/1.0/search/?dataset=bxl_food_trucks", function (results) {
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (var i =0; i < results.records.length; i++) {
if (results.records[i].fields.lundi != undefined) {
locations[i] = {
'name' : results.records[i].fields.lundi,
'lat' : results.records[i].fields.latitude_breedtegraad,
'lng' : results.records[i].fields.longitude_lengtegraad
};
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i].lat, locations[i].lng),
map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i].name );
infowindow.open(map, marker);
}
})(marker, i));
}
}
});

// Try HTML5 geolocation.
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};

var image = 'image/truck.png';
marker = new google.maps.Marker({
position: new google.maps.LatLng(position.coords.latitude, position.coords.longitude),
map: map,
icon: image
});

}, function() {
handleLocationError(true, infoWindow, map.getCenter());
});
} else {
// Browser doesn't support Geolocation
handleLocationError(false, infoWindow, map.getCenter());
}
}

function handleLocationError(browserHasGeolocation, infoWindow, pos) {
infoWindow.setPosition(pos);
infoWindow.setContent(browserHasGeolocation ?
'Error: The Geolocation service failed.' :
'Error: Your browser doesn\'t support geolocation.');
}

</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyC9y0i-GnLeSP9O5SwJJQfd-nNiYv2wWMM&callback=initMap">
</script>

<script
src="https://code.jquery.com/jquery-1.12.4.min.js"
integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ="
crossorigin="anonymous"></script>

</body>
</html>

DébutPage précedente
1
Page suivantePage suivante
Sujet fermé pour la raison suivante : Titre explicite, merci. +paste "propre" du code, +question precise
Infos 0 connecté(s)

Gestion du forum

Modérateurs : godrik, LGV
Contacter les modérateurs - Règles du forum

Sujets à ne pas manquer

La vidéo du moment