2014-03-05 92 views
0

嗨即時通訊新的谷歌地圖和JQuery和我來到了一個問題,我需要觸發或重點設置地圖焦點時單選按鈕的變化。有人可以幫助我處理這種情況嗎?列表中的單選按鈕由.each循環填充

代碼段:

function initialize() { 
      var minZoomLevel = 4; 
      var zooms = 7; 
      geocoder = new google.maps.Geocoder(); 
      geocode = new google.maps.Geocoder(); 

      // Used to Set the Center of the Maps on the Logged User 
      $.getJSON('/Dashboard/LoadAddress', function Geocoding(address) { 
       $.each(address, function() { 

        customerlocationID = this["ID"]; 
        var currValAddress = this["AddressLine1"]; 
        var Latitude = this["Latitude"]; 
        var Longitude = this["Longitude"]; 
        LatLang = new google.maps.LatLng(Latitude, Longitude); 
        var addresse = { 
         zoom: 16, 
         center: LatLang, 
         mapTypeId: google.maps.MapTypeId.ROADMAP 
        }; 
        map = new google.maps.Map(document.getElementById('map'), addresse); 

        var link = $('<input type="radio" name="a"/><label>'+ currValAddress+'</label>').data('location', LatLang); 
        $('#initialPlace').append($('<li id=\'List\' class=\'List\'>').append(link)); 
        link.on('click', function (event) { 
         var $t = $(event.target); 
         if ($t.hasClass('checked')) { 
          map.setCenter(LatLang); 
          $t.removeAttr('checked'); 
         } 
         $('input[type="radio"][name="' + $t.prop('name') + '"]').not($t).removeClass('checked'); 
         $t.toggleClass('checked'); 
        }).filter(':checked').addClass('checked'); 

        // Bounds for North America 
        var strictBounds = new google.maps.LatLngBounds(
         new google.maps.LatLng(15.70, -160.50), 
         new google.maps.LatLng(68.85, -55.90)); 

        // Listen for the dragend event 
        google.maps.event.addListener(map, 'dragend', function() { 
         if (strictBounds.contains(map.getCenter())) return; 
         // We're out of bounds - Move the map back within the bounds 

         var c = map.getCenter(), 
         x = c.lng(), 
         y = c.lat(), 
         maxX = strictBounds.getNorthEast().lng(), 
         maxY = strictBounds.getNorthEast().lat(), 
         minX = strictBounds.getSouthWest().lng(), 
         minY = strictBounds.getSouthWest().lat(); 

         if (x < minX) x = minX; 
         if (x > maxX) x = maxX; 
         if (y < minY) y = minY; 
         if (y > maxY) y = maxY; 

         map.setCenter(new google.maps.LatLng(y, x)); 
        }); 

        // Limit the zoom level 
        google.maps.event.addListener(map, 'zoom_changed', function() { 
         if (map.getZoom() < minZoomLevel) map.setZoom(minZoomLevel); 
        }); 
       }); 
      }); 
      if (customerlocationID != 0) { 

       codeAddress(customerlocationID, Rad); 
      } 

     } 

回答