Created
January 19, 2016 20:20
-
-
Save dmehrotra/e1bf2789ae4e2d245940 to your computer and use it in GitHub Desktop.
socketmap
This file contains hidden or 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>Simple markers</title> | |
<script src="https://cdn.socket.io/socket.io-1.3.5.js"></script> | |
<style> | |
html, body { | |
height: 100%; | |
margin: 0; | |
padding: 0; | |
} | |
#map { | |
height: 100%; | |
} | |
#tweet{ | |
position:absolute; | |
z-index:100; | |
background:white; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="tweet"></div> | |
<div id="map"></div> | |
<script> | |
var map; | |
var socket = io.connect('http://localhost:3000'); | |
socket.on('tweet', function (data) { | |
document.getElementById('tweet').innerHTML = data.tweet.text | |
if (data.tweet.coordinates) { | |
var latLng = {lat: data.tweet.coordinates.coordinates[1], lng: data.tweet.coordinates.coordinates[0]} | |
map.setCenter(latLng); | |
map.setZoom(14); | |
console.log(data.tweet.coordinates.coordinates[0]); | |
var marker = new google.maps.Marker({ | |
position: latLng, | |
map: map, | |
title: '' | |
}); | |
}; | |
}); | |
function init() { | |
map = new google.maps.Map(document.getElementById('map'), { | |
zoom: 4, | |
center: {lat: 40.7127, lng: -73.0059} | |
}); | |
} | |
</script> | |
<script async defer | |
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCsYKGxW1tT39r89OGt_FGND4J07eHLGOw&callback=init"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment