Guest User

Google Map v3 (offsetting markers in same coordinates)

a guest
Jul 9th, 2013
1,044
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.46 KB | None | 0 0
  1.     function load() {
  2.       var map = new google.maps.Map(document.getElementById("map"), {
  3. //        center: new google.maps.LatLng(38.548165,-96.416016),
  4. //      center: new google.maps.LatLng(35.65897,-101.390762),
  5. center: new google.maps.LatLng(35.738222,-101.493545),
  6.         zoom: 15,
  7.         mapTypeId: 'roadmap'
  8.       });
  9.       var infoWindow = new google.maps.InfoWindow;
  10.  
  11.       // Change this depending on the name of your PHP file
  12.       downloadUrl("10same.xml", function(data) {
  13.         var xml = data.responseXML;
  14.         var markers = xml.documentElement.getElementsByTagName("marker");
  15.         for (var i = 0; i < markers.length; i++) {
  16.           var city = markers[i].getAttribute("city");
  17.           var fullstate = markers[i].getAttribute("fullstate");
  18.           var zip = markers[i].getAttribute("zip");
  19.           var point = new google.maps.LatLng(
  20.         parseFloat(markers[i].getAttribute("latitude")),
  21.         parseFloat(markers[i].getAttribute("longitude")));
  22.  
  23.  
  24.  
  25. //================================================================
  26. // The var point above renders the marker in their locations.
  27. // If I comment it out, I found I can also render them with:
  28. //  realLat = markers[i].getAttribute("latitude");
  29. //  realLon = markers[i].getAttribute("longitude");
  30. //  var point = new google.maps.LatLng(realLat, realLon);
  31. //================================================================
  32.  
  33.  
  34.  
  35.           var html = "<b>" + city + "</b> <br/>" + fullstate;
  36.           var icon = customIcons[fullstate] || {};
  37.           var marker = new google.maps.Marker({
  38.             map: map,
  39.             position: point,
  40.             icon: icon.icon,
  41.             shadow: icon.shadow
  42.           });
  43.         bindInfoWindow(marker, map, infoWindow, html);  
  44.         }
  45.       });
  46.     }
  47.  
  48.     function bindInfoWindow(marker, map, infoWindow, html) {
  49.       google.maps.event.addListener(marker, 'click', function() {
  50.         infoWindow.setContent(html);
  51.         infoWindow.open(map, marker);
  52.       });
  53.     }
  54.  
  55.     function downloadUrl(url, callback) {
  56.       var request = window.ActiveXObject ?
  57.           new ActiveXObject('Microsoft.XMLHTTP') :
  58.           new XMLHttpRequest;
  59.  
  60.       request.onreadystatechange = function() {
  61.         if (request.readyState == 4) {
  62.           request.onreadystatechange = doNothing;
  63.           callback(request, request.status);
  64.         }
  65.       };
  66.  
  67.       request.open('GET', url, true);
  68.       request.send(null);
  69.     }
  70.  
  71.     function doNothing() {}
Add Comment
Please, Sign In to add comment