-
-
Save tc523/5df9c08b471fb62d79ecf9eb75eb39dd to your computer and use it in GitHub Desktop.
Sensors Location Data HTML and Javascript Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"> | |
<meta charset="utf-8"> | |
<title>Sensors Location Data on Map</title> | |
<style> | |
/* Always set the map height explicitly to define the size of the div | |
* element that contains the map. */ | |
#map { | |
height: 100%; | |
} | |
/* Optional: Makes the sample page fill the window. */ | |
html, body { | |
height: 100%; | |
margin: 0; | |
padding: 0; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="map"></div> | |
<script> | |
function initMap() { | |
//create an empty array to add all locations | |
var locationsDataArray = []; | |
//your lats, longs go here! put as many as you want... | |
locationsDataArray.push({lat: 39.953660, lng: -75.189459}); | |
locationsDataArray.push({lat: 39.955087, lng: -75.188783}); | |
//choose the center for your map | |
var centerLatLng = {lat: 39.955854, lng: -75.187560}; | |
//create the map | |
var map = new google.maps.Map(document.getElementById('map'), { | |
zoom: 4, | |
center: centerLatLng | |
}); | |
//loop through your array to create markers on the map for each one | |
locationsDataArray.forEach(function(location){ | |
//create new marker | |
var marker = new google.maps.Marker({ | |
position: new google.maps.LatLng(location.lat, location.lng), | |
map: map, | |
title: 'Sensors Locations Data!' | |
}); | |
}) | |
} | |
</script> | |
<script async defer | |
src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"> | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment