Skip to content

Instantly share code, notes, and snippets.

@nelyj
Created July 20, 2013 19:36
Show Gist options
  • Save nelyj/6046173 to your computer and use it in GitHub Desktop.
Save nelyj/6046173 to your computer and use it in GitHub Desktop.
Generar multiples puntos con jquery y Google maps, los datos son obtenidos desde un JSON ;)
var map;
function initialize() {
var mapOptions = {
zoom: 10,
scaleControl: true,
center: new google.maps.LatLng(-33.5357766,-70.5617116),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
//locations.js is a array of routes of my application
$.getJSON('/locations.json', function(data){
$.each(data, function(i,objeto){
direccion(map, objeto);
});
});
}
function direccion(map, objeto){
console.log(objeto);
var marker = new google.maps.Marker({
map: map,
position: new google.maps.LatLng(objeto.latitude, objeto.longitude),
bounds: true
});
var infowindow = new google.maps.InfoWindow();
infowindow.setContent(objeto.address);
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, marker);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
<!DOCTYPE html>
<html>
<head>
<title>Multiples puntos en Google maps</title>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
</head>
#map-canvas
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment