This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

sidebar-gmap.php

By: demlasjr on Aug 5th, 2012  |  syntax: JavaScript  |  size: 4.55 KB  |  views: 134  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <div id="gmap" class="mapblock">
  2.  
  3.     <?php
  4.     // check to see if ad is legacy or not and then assemble the map address
  5.     if ( get_post_meta($post->ID, 'location', true) )
  6.         $make_address = get_post_meta($post->ID, 'location', true);
  7.     else
  8.         $make_address = get_post_meta($post->ID, 'cp_street', true) . '&nbsp;' . get_post_meta($post->ID, 'cp_city', true) . '&nbsp;' . get_post_meta($post->ID, 'cp_state', true) . '&nbsp;' . get_post_meta($post->ID, 'cp_zipcode', true);
  9.  
  10.                 $coordinates = cp_get_geocode( $post->ID );
  11.     ?>
  12.  
  13.     <script type="text/javascript">var address = "<?php echo esc_js($make_address); ?>";</script>
  14.  
  15.                 <?php cp_google_maps_js($coordinates); ?>
  16.  
  17.     <!-- google map div -->
  18.     <div id="map"></div>
  19.  
  20. </div>
  21.  
  22.  
  23. <?php
  24. // Google map on single page
  25. function cp_google_maps_js($coordinates) {
  26. ?>
  27.  <script type="text/javascript">
  28. //<![CDATA[
  29.     jQuery(document).ready(function($) {
  30.         $('#map').hide();
  31.         load();
  32.         $('#map').fadeIn(1000)
  33.         codeAddress();
  34.     });
  35.  
  36.                 <?php
  37.                 if(!empty($coordinates) && is_array($coordinates)) {
  38.                         echo 'var SavedLatLng = new google.maps.LatLng('.$coordinates['lat'].', '.$coordinates['lng'].');';
  39.                         $location_by = "'latLng':SavedLatLng";
  40.                         $marker_position = "SavedLatLng";
  41.                 } else {
  42.                         $location_by = "'address': address";
  43.                         $marker_position = "results[0].geometry.location";
  44.                 }
  45.                 ?>
  46.  
  47.     //var directionDisplay;
  48.     //var directionsService = new google.maps.DirectionsService();
  49.     var map = null;
  50.     var geocoder = null;
  51.     var fromAdd;
  52.     var toAdd;
  53.     var redFlag = "<?php echo get_bloginfo('template_directory') ?>/images/red-flag.png";
  54.     var shadow = "<?php echo get_bloginfo('template_directory') ?>/images/red-flag-shadow.png";
  55.     var noLuck = "<?php echo get_bloginfo('template_directory') ?>/images/gmaps-no-result.gif";
  56.     //var title = "<?php esc_js(the_title()); ?>";
  57.     var contentString = '<div id="mcwrap"><span><?php esc_js(the_title()); ?></span><br />' + address + '</div>';
  58.  
  59.     function load() {
  60.         geocoder = new google.maps.Geocoder();
  61.         //directionsDisplay = new google.maps.DirectionsRenderer();
  62.         var newyork = new google.maps.LatLng(40.69847032728747, -73.9514422416687);
  63.         var myOptions = {
  64.             zoom: 14,
  65.             center: newyork,
  66.             mapTypeId: google.maps.MapTypeId.ROADMAP,
  67.             mapTypeControlOptions: {
  68.                 style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
  69.             }
  70.         }
  71.         map = new google.maps.Map(document.getElementById('map'), myOptions);
  72.         //directionsDisplay.setMap(map);
  73.     }
  74.  
  75.  
  76.     function codeAddress() {
  77.         geocoder.geocode( { <?php echo $location_by; ?> }, function(results, status) {
  78.           if (status == google.maps.GeocoderStatus.OK) {
  79.             map.setCenter();
  80.  
  81.             var marker = new google.maps.Marker({
  82.                 map: map,
  83.                 icon: redFlag,
  84.                 shadow: shadow,
  85.                 //title: title,
  86.                 animation: google.maps.Animation.DROP,
  87.                 position: <?php echo $marker_position; ?>
  88.             });
  89.  
  90.             var infowindow = new google.maps.InfoWindow({
  91.                 maxWidth: 270,
  92.                 content: contentString,
  93.                 disableAutoPan: false
  94.             });
  95.  
  96.             infowindow.open(map, marker);
  97.  
  98.             google.maps.event.addListener(marker, 'click', function() {
  99.               infowindow.open(map,marker);
  100.             });
  101.  
  102.           } else {
  103.             (function($) {
  104.                 $('#map').append('<div style="height:400px;background: url(' + noLuck + ') no-repeat center center;"><p style="padding:50px 0;text-align:center;"><?php echo esc_js(__('Sorry, the address could not be found.', 'anuncios')); ?></p></div>');
  105.                 return false;
  106.             })(jQuery);
  107.           }
  108.         });
  109.       }
  110.  
  111.     function showAddress(fromAddress, toAddress) {
  112.         calcRoute();
  113.         calcRoute1();
  114.     }
  115.     function calcRoute() {
  116.         var start = document.getElementById("fromAdd").value;
  117.         var end = document.getElementById("toAdd").value;
  118.         var request = {
  119.             origin: start,
  120.             destination: end,
  121.             travelMode: google.maps.DirectionsTravelMode.DRIVING
  122.         };
  123.         directionsService.route(request, function(response, status) {
  124.             if (status == google.maps.DirectionsStatus.OK) {
  125.                 directionsDisplay.setDirections(response);
  126.             }
  127.         });
  128.     }
  129. //]]>
  130. </script>
  131.  
  132.  
  133. <?php
  134.  
  135. }
  136.  
  137. ?>
clone this paste RAW Paste Data