Guest User

Untitled

a guest
Sep 23rd, 2012
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var markersArray = [];
  2.    
  3.     function addMarker(location) {
  4.         marker = new google.maps.Marker({
  5.             position: location,
  6.             map: map
  7.         });
  8.         markersArray.push(marker);
  9.     }
  10.    
  11.     function deleteOverlays() {
  12.         if (markersArray) {
  13.             for (i in markersArray) {
  14.                 markersArray[i].setMap(null);
  15.             }
  16.             markersArray.length = 0;
  17.         }
  18.     }
  19.    
  20.     var map = new google.maps.Map( document.getElementById("map_canvas"),  {
  21.         center: new google.maps.LatLng(47.997337,7.841653),
  22.         zoom: 5,
  23.         mapTypeId: google.maps.MapTypeId.ROADMAP,
  24.         panControl: false,
  25.         streetViewControl: false,
  26.         mapTypeControl: false
  27.        
  28.     });
  29.    
  30.     var temp_address = $('input[name=input_location]').val();
  31.     var temp_coords = $('input[name=input_coordinates]').val();
  32.  
  33.     $('input[name=other_address]').change(function() {
  34.         if($('input[name=input_location]').val()){
  35.             $('input[name=input_location]').val('');
  36.             $('input[name=input_coordinates]').val('');
  37.         }else{
  38.             $('input[name=input_location]').val(temp_address);
  39.             $('input[name=input_coordinates]').val(temp_coords);
  40.         }
  41.     });
  42.    
  43.     var geocoder = new google.maps.Geocoder();
  44.     geocoder.geocode({
  45.         address : $('input[name=input_location]').val(),
  46.         region: 'no'
  47.     }, function(results, status) {
  48.         if (status.toLowerCase() == 'ok') {
  49.             var coords = new google.maps.LatLng(
  50.                 results[0]['geometry']['location'].lat(),
  51.                 results[0]['geometry']['location'].lng()
  52.                 );
  53.  
  54.             map.setCenter(coords);
  55.             map.setZoom(14);
  56.             addMarker(coords);
  57.                
  58.             $('input[name=input_coordinates]').val( coords.lat() + ', ' + coords.lng() );
  59.            
  60.             $('input[name=other_address]').change(function(){
  61.                 if($('input[name=other_address]').is(':checked')){
  62.                     deleteOverlays();
  63.                     map.setZoom(5);
  64.                 }else {
  65.                     map.setCenter(coords);
  66.                     map.setZoom(14);
  67.                     addMarker(coords);
  68.                 }
  69.             });
  70.            
  71.         }
  72.     }
  73.     );
Advertisement
Add Comment
Please, Sign In to add comment