点击链接后,在lightbox(colorbox,shadowbox等)中初始化google maps api

时间:2014-10-31 05:56:58

标签: google-maps lightbox google-geocoder

我有一个地址链接列表:

<a href="#location_google" data-address="Moscow" class="openmap"><span>Address</span></a>
<a href="#location_google" data-address="London" class="openmap"><span>Address</span></a>
<a href="#location_google" data-address="Tel Aviv" class="openmap"><span>Address</span></a>

这是我的GMap脚本(来自here):

function initialize() {
      geocoder = new google.maps.Geocoder();
      var latlng = new google.maps.LatLng(-34.397, 150.644);
      codeAddress();
      var mapOptions = {
        zoom: 12,
        center: latlng,
            zoomControl: true,
            zoomControlOptions: {
                style: google.maps.ZoomControlStyle.LARGE
            },
            scrollwheel: false
      }
      map = new google.maps.Map(document.getElementById('map_wrap'), mapOptions);

    }

    function codeAddress() {
      var address = document.getElementById('address').value;
      geocoder.geocode( { 'address': address}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
          map.setCenter(results[0].geometry.location);
          var marker = new google.maps.Marker({
              map: map,
              position: results[0].geometry.location
          });
        } else {
          alert('Geocode was not successful for the following reason: ' + status);
        }
      });
    }

我输入id =“address”为空,此输入将保存我的地址“data-address”参数:

<div class="hidden">
    <div id="location_google">
        <div id="map_wrap"></div>
    </div>
</div>

我需要点击我的地址链接后,获取 jQuery(this)地址,将其输入id =“address”输入,然后在某个灯箱中打开它。我在lightbox之前尝试过,但它对我不起作用......

点击时初始化灯箱:

jQuery("a.openmap").tosrus();

0 个答案:

没有答案