Advertisement
Guest User

Untitled

a guest
Jul 24th, 2014
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
  2. <script>
  3. var map;
  4. function initialize() {
  5. var mapOptions = {
  6. zoom: 7,
  7. center: new google.maps.LatLng(-44,-74),
  8. mapTypeId: google.maps.MapTypeId.ROADMAP
  9. };
  10.  
  11. var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
  12.  
  13. var projects = [];
  14.  
  15. <?php $terrenos = get_terrenos(); ?>
  16.  
  17. <?php foreach ($terrenos as $terreno) { ?>
  18. projects.push({
  19. lat: <?php echo isset($terreno->latitud) ? "'" . $terreno->latitud . "'": '' ?> ,
  20. lon: <?php echo isset($terreno->longitud) ? "'" . $terreno->longitud . "'": '' ?>,
  21. info: <?php echo isset($terreno->name) ? "\"" . $terreno->name . "\"" : '' ?>,
  22. marker : null
  23. });
  24. <?php } ?>
  25.  
  26. // console.log(projects);
  27.  
  28. var InfoWindow = new google.maps.InfoWindow(
  29. {
  30. content: '...'
  31. });
  32.  
  33. for( var key in projects ){
  34. var project = projects[key];
  35.  
  36. project.marker = new google.maps.Marker({
  37. position: new google.maps.LatLng(project.lat, project.lon),
  38. map: map,
  39. info: project.info
  40. });
  41.  
  42. google.maps.event.addListener(project.marker, 'click', function(){
  43. InfoWindow.setContent(this.info);
  44. InfoWindow.open(map, this);
  45. });
  46. }
  47.  
  48. }
  49.  
  50. google.maps.event.addDomListener(window, 'load', initialize);
  51.  
  52. </script>
  53.  
  54. <div id="map-canvas" style="width:480px; height:418px; margin-top:1px; float:left; margin-right:10px;"></div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement