Advertisement
developerjustin

Untitled

Apr 25th, 2014
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var mapcanvas = "geocodepreview";
  2.  
  3. jQuery(document).ready(function($) {
  4.  
  5.     jQuery.fn.codeAddress = function () {
  6.  
  7.         var geocoder;
  8.         var map;
  9.  
  10.  
  11.       geocoder = new google.maps.Geocoder();
  12.       var latlng = new google.maps.LatLng(-34.397, 150.644);
  13.       var myOptions = {
  14.         backgroundColor: '#EAEAEA',
  15.         mapTypeControl: false,
  16.         zoom: 11,
  17.         center: latlng,
  18.         mapTypeId: google.maps.MapTypeId.ROADMAP
  19.       }
  20.       map = new google.maps.Map(document.getElementById(mapcanvas), myOptions);
  21.  
  22.  
  23.       var address = $('input[name="dr_cd_address"]').attr('value') + ' ' + $('input[name="dr_cd_city"]').attr('value') + ',' + $('input[name="dr_cd_state"]').attr('value') + ' ' + $('input[name="dr_cd_zipcode"]').attr('value');;
  24.       geocoder.geocode( { 'address': address}, function(results, status) {
  25.         if (status == google.maps.GeocoderStatus.OK) {
  26.           map.setCenter(results[0].geometry.location);
  27.           var marker = new google.maps.Marker({
  28.               map: map,
  29.               position: results[0].geometry.location
  30.           });
  31.             var fullLatLon = results[0].geometry.location;
  32.            
  33.             $('input[name="dr_cd_latlon"]').attr('value',fullLatLon);
  34.         } else {
  35.           alert("Geocode was not successful for the following reason: " + status);
  36.         }
  37.       });
  38.     }
  39.  
  40.     $('#geocode').bind('click', function() {
  41.         $(document).codeAddress();
  42.     });
  43.  
  44.    
  45.  
  46. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement