Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2015
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. <apex:page standardController="Account">
  2.  
  3. <head>
  4.  
  5. <script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=false"></script>
  6. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
  7. <script type="text/javascript">
  8.  
  9. $(document).ready(function() {
  10.  
  11. var myOptions = {
  12. zoom: 15,
  13. mapTypeId: google.maps.MapTypeId.ROADMAP,
  14. mapTypeControl: false
  15. }
  16.  
  17. var map;
  18. var marker;
  19.  
  20. var geocoder = new google.maps.Geocoder();
  21. var address = "{!Account.BillingStreet}, " + "{!Account.BillingCity}, " + "{!Account.BillingPostalCode}, " + "{!Account.BillingCountry}";
  22.  
  23. var infowindow = new google.maps.InfoWindow({
  24. content: "<b>{!Account.Name}</b><br>{!Account.BillingStreet}<br>{!Account.BillingCity}, {!Account.BillingPostalCode}<br>{!Account.BillingCountry}"
  25. });
  26.  
  27. geocoder.geocode( { address: address}, function(results, status) {
  28. if (status == google.maps.GeocoderStatus.OK && results.length) {
  29. if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
  30.  
  31. //create map
  32. map = new google.maps.Map(document.getElementById("map"), myOptions);
  33.  
  34. //center map
  35. map.setCenter(results[0].geometry.location);
  36.  
  37. //create marker
  38. marker = new google.maps.Marker({
  39. position: results[0].geometry.location,
  40. map: map,
  41. title: "{!Account.Name}"
  42. });
  43.  
  44. //add listeners
  45. google.maps.event.addListener(marker, 'click', function() {
  46. infowindow.open(map,marker);
  47. });
  48. google.maps.event.addListener(infowindow, 'closeclick', function() {
  49. map.setCenter(marker.getPosition());
  50. });
  51.  
  52. }
  53.  
  54. } else {
  55. $('#map').css({'height' : '15px'});
  56. $('#map').html("Oops! {!Account.Name}'s billing address could not be found, please make sure the address is correct.");
  57. resizeIframe();
  58. }
  59. });
  60.  
  61. function resizeIframe() {
  62. var me = window.name;
  63. if (me) {
  64. var iframes = parent.document.getElementsByName(me);
  65. if (iframes && iframes.length == 1) {
  66. height = document.body.offsetHeight;
  67. iframes[0].style.height = height + "px";
  68. }
  69. }
  70. }
  71.  
  72. });
  73. </script>
  74.  
  75. <style>
  76. #map {
  77. font-family: Arial;
  78. font-size:12px;
  79. line-height:normal !important;
  80. height:250px;
  81. background:transparent;
  82. }
  83. </style>
  84.  
  85. </head>
  86.  
  87. <body>
  88. <div id="map"></div>
  89. </body>
  90. </apex:page>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement