【发布时间】:2015-11-25 16:03:56
【问题描述】:
我正在尝试为我的房地产网站实施 GMap,其中每个属性都有自己的地图,该地图基于位置纬度和经度以及自定义标记图标。问题是初始化后地图没有以标记图标为中心。我也阅读了很多帖子,但任何解决方案都不适合我,所以如果有人有能力提供帮助,我会很高兴找到一个可行的解决方案。
这是我到目前为止所做的。
视图文件中的代码 - 我将数据属性用于动态位置 (LatLong) 值,这适用于我在属性管理中的自定义字段。
<div class="property">
<ul class="tabs clearfix">
<li class="current">Tab 1</li>
<li>Tab 2</li>
<li>Tab 3</li>
</ul>
<div class="box visible">
Tab 1 content
</div>
<div class="box">
Tab 2 content
</div>
<div class="box">
<div id="map" class="property-map" data-latitude="xxxxxx" data-longitude="xxxxxx"></div>
</div>
</div>
jQuery:
$('ul.tabs').on('click', 'li:not(.current)', function() {
$(this).addClass('current').siblings().removeClass('current')
.parents('div.property').find('div.box').eq($(this).index()).fadeIn(150).siblings('div.box').hide();
})
$('ul.tabs').on('click', 'li:not(.current)', function() {
google.maps.event.trigger(map, "resize");
})
CSS:
.property { margin-top:30px; }
.property .box { display: none; }
.property .box.visible { display: block; }
.property .tabs li { position:relative; float:left; margin:0 -1px 0 0; padding:14px 35px; text-transform:uppercase; font-weight:600; color:#666; border:1px solid #e9e9e9; cursor:pointer; transition: color 0.3s ease-in-out; -webkit-transition: color 0.3s ease-in-out;}
.property .tabs li:hover { color:#000; }
.property .tabs li.current { margin-top:-2px; color:#000; border-top:3px solid #fcb042; border-bottom:1px solid #fff; background: #f0f0f0;}
.property .box { margin-top:-1px; padding:16px 19px 18px; line-height:20px; color:#666; border:1px solid #e9e9e9;}
.property-map { width:800px; height: 420px; }
主索引文件:
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"" type="text/javascript"></script>
<script type="text/javascript">
function initialize_map() {
var latitude = $('#map').data('latitude');
var longitude = $('#map').data('longitude');
var myLatlng = new google.maps.LatLng(latitude,longitude);
var mapOptions = {
zoom: 17,
scrollwheel: true,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.SATELLITE
};
var map = new google.maps.Map(document.getElementById('map'), mapOptions);
var marker = new google.maps.Marker({
position: myLatlng,
icon: '../images/new-marker.png',
title:"Marker title",
map: map
});
}
google.maps.event.addDomListener(window, 'load', initialize_map);
</script>
【问题讨论】:
标签: javascript jquery google-maps-api-3 tabs