0

该网站在这里: http: //keenanautobody.com/mobile/index.php

在我使用 jQuery 移动生成的后退按钮/浏览器后退按钮返回页面后,我的信息窗口无法正常工作(在从一个标记处点击“获取方向”链接之后)。

以为是jqm的问题,把整个地图初始化分解成几个函数,然后在返回页面的时候再次运行click事件委托器。在添加侦听器之前,我使用隐藏的输入字段来侦听地图是否已加载。我发现返回页面时jqm页面事件pageshow没有触发,所以我将该函数附加到beforepageshow。那是开火,但标记信息窗口仍然无法返回。

该网站说我的问题似乎是主观的,并且可能会被关闭,无论这意味着什么。

这是我的地图代码:

initLocsMap();
bounds = new google.maps.LatLngBounds();
addMapMarkers();
bounds.extend(userPos);
map.fitBounds(bounds);
infowindow = new google.maps.InfoWindow();
$('#map_loaded').val('loaded').trigger('change');
reportClosest();

var geocoder;
var map;
var markers = [];
var userPos;
var infowindow;
var bounds;

// create map with user position marked at center
function initLocsMap()
{
    userPos = new google.maps.LatLng(user_lat, user_long);
    var options = 
    {
        zoom: 16,
        center: userPos,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    map = new google.maps.Map(document.getElementById("map_canvas_home"), options);

    // set user marker
    var userMarker = new google.maps.Marker(
    {
        position: userPos,
        map: map,
        icon: 'https://maps.gstatic.com/mapfiles/ms2/micons/ylw-pushpin.png'
    });
}

// add several markers to map and extend bounds
function addMapMarkers()
{
    for (var i = 0; i < locData.locsLength(); i++)
    {
        var point = new google.maps.LatLng(locData.getByKey(i,'lat'), locData.getByKey(i,'long'));
        markers[i] = new google.maps.Marker({
            position: point,
            map: map
        });
        bounds.extend(point);
    }
}

function addMapInfoWindows()
{
    alert('add info windows');
    for (var i = 0; i < locData.locsLength(); i++)
    {
        var marker = markers[i];
        google.maps.event.addListener(marker, 'click', (function(marker, i) 
        {
            return function() 
            {
                var address = locData.getByKey(i,'address');
                var ad1ad2 = address.split(', ');
                var ad1 = (ad1ad2.shift());
                var ad2 = (ad1ad2.join(', '));
                infowindow.setContent(locData.getByKey(i,'full_name')+"<br>"+ad1+"<br>"+ad2+"<br>"+locData.getByKey(i,'duration_text')+' - '+locData.getByKey(i,'distance_text')+"<br>"+"<a href=\"directions.php?location="+locData.getByKey(i,'name')+"\">Get Directions</a>");
                infowindow.open(map, marker);
            }
        })(marker, i));
    }
}

$(document)./*off('pageinit', '#home').*/on('pagebeforeshow', '#home', function(event)
{
    alert('pagebeforeshow');
    if ($('#map_loaded').val() == 'loaded')
    {
        alert('loaded');
        addMapInfoWindows();
    }
    else
    {
        $('#map_loaded').change(function()
        {
            alert('change');
            addMapInfoWindows();
        })
    }
})
4

0 回答 0