Posted By

ryarwood on 07/09/10


Tagged

javascript google xml map


Versions (?)

Google Map


 / Published in: JavaScript
 

  1. <body onload"load()" onunload="GUnload()">
  2.  
  3. <div id="map" style="width: 622px; height: 320px" class="mapBlock"></div>
  4.  
  5. <script type="text/javascript">
  6. //<![CDATA[
  7.  
  8. if (GBrowserIsCompatible()) {
  9.  
  10. // A function to create the marker and set up the event window
  11. // Dont try to unroll this function. It has to be here for the function closure
  12. // Each instance of the function preserves the contends of a different instance
  13. // of the "marker" and "html" variables which will be needed later when the event triggers.
  14. function createMarker(point,html) {
  15. var marker = new GMarker(point);
  16. GEvent.addListener(marker, "click", function() {
  17. marker.openInfoWindowHtml(html);
  18. });
  19. return marker;
  20. }
  21.  
  22. // Display the map, with some controls and set the initial location
  23. var map = new GMap2(document.getElementById("map"));
  24. map.addControl(new GLargeMapControl());
  25. map.addControl(new GMapTypeControl());
  26. map.setCenter(new GLatLng(37.332179,-122.032571),11);
  27.  
  28. // Set up three markers with info windows
  29.  
  30. var point = new GLatLng(37.332179,-122.032571);
  31. var marker = createMarker(point,'<div style="width:240px; font-size: 11px; font-family: Verdana, Arial, Helvetica, sans-serif; color: #000000;">Cupertino Inn<br \/>10889 N De Anza Blvd<br \/>Cupertino, CA 95014<br \/><a href="http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=cupertino+inn&sll=37.0625,-95.677068&sspn=46.005754,76.289063&ie=UTF8&z=13&iwloc=A">Directions<\/a><\/div>')
  32. map.addOverlay(marker);
  33.  
  34. }
  35.  
  36. // display a warning if the browser was not compatible
  37. else {
  38. alert("Sorry, the Google Maps API is not compatible with this browser");
  39. }
  40.  
  41. // This Javascript is based on code provided by the
  42. // Blackpool Community Church Javascript Team
  43. // http://www.commchurch.freeserve.co.uk/
  44. // http://econym.googlepages.com/index.htm
  45.  
  46. //]]>
  47. </script>

Report this snippet  

You need to login to post a comment.