0

我正在一个项目中为手机提供地图。现在我正在尝试使用 iPhone。

它工作正常,当我加载我的第一页时,我可以看到一张包含我的位置的地图,市场每 10 秒刷新一次并移动到我的下一个位置。

有时当我切换页面并返回第一页时,地图没有完全显示。如果我移动地图,它会移动,但地图的某些图像仍未显示。

我也在使用 jquery mobe。

我还注意到,每次返回第一张地图时,都会重新加载地图。

有没有办法加载一次地图?那么如何检查我的地图是否已加载?

这是我的代码

$('#home').live('pagebeforeshow', function(e){

    // Resize #mapHome (#mapHome = Sreen hight - footer - header)
    $('#mapHome').css('height', Resize.content()-2 +'px');

        // extract les id des modules existants
        navigator.geolocation.getCurrentPosition(function(position){

            showMap('mapHome',position.coords.latitude, position.coords.longitude);
            //console.log(position.coords.latitude, position.coords.longitude);

        }, 
        function(){
            //error
        }, 
        {

                enableHighAccuracy  : true,
                maximumAge          : 30000
                //maximumAge:Infinity
        });



        // Place and move the marker regarding to my position and deplacement
        var track_id = "me";
        Tracking.watch_id = navigator.geolocation.watchPosition(
        // Success
        function(position){
            console.log('WatchPosition called');
            var lat = position.coords.latitude;
            var long = position.coords.longitude;

            var latLng = new Array();
            latLng[0] = lat;
            latLng[1] = long;

            //Tracking.myCoordinates.push(lat,long);
            Tracking.myCoordinates.push(latLng);
            addMarker(lat, long);

        },
        // Error
        showError,
        { 
            frequency: 1000

        });

})

我刚把那条线改成

$('#home').live('pageshow', function(e){... code...}

它会变得更好,但我不确定-

这是我的函数 showMap() 的代码

function showMap(canvas,lat,long){
            var latLng = new google.maps.LatLng(lat,long);
            // Google Map options       var myOptions = {
          zoom: 19,
          //zoomControl : 1,
          center: latLng,
          mapTypeId: google.maps.MapTypeId.ROADMAP////ROADMAP, SATELLITE, HYBRID and TERRAIN        };      

        // Create the Google Map, set options       Tracking.mapy = new google.maps.Map(document.getElementById(canvas), myOptions);

}

这是代码 addMarker()

function addMarker(lat, long){

        Tracking.mapBounds = new google.maps.LatLngBounds();

        // Clean previous markers
        for (var i = 0; i < Tracking.markers.length; i++ ) {
            Tracking.markers[i].setMap(null);       
        }         

        // Add the owner's marker
        var latitudeAndLongitude = new google.maps.LatLng(lat, long);
        var image = "img/iconGoogleMap/phones.png";
        marker = new google.maps.Marker({
            title   : 'me',
            //animation: google.maps.Animation.DROP, //BOUNCE
            position: latitudeAndLongitude,
            map     : Tracking.mapy,
            icon : image
        });
        Tracking.markers.push(marker);
        //Tracking.markers.push(marker);
        //console.log(localStorage.getItem('mapToDisplay'));

        /*  ADDING MODULES MAKERS */
        // Store the ID of available module.
        modulesJSON = Modules.get('bipme');

        for (var i = 0; i < modulesJSON['modules'].length; i++) {

            console.log('module id = ' +modulesJSON['modules'][i].id);
            console.log('Module ' + modulesJSON['modules'][i].id + ' position : ' + ModulesPos.module(modulesJSON['modules'][i].id));

            nlatLong = ModulesPos.module(modulesJSON['modules'][i].id).split(",");
            var LatitudeAndLongitudeModules = new google.maps.LatLng(nlatLong[0],nlatLong[1]);
            var image = "img/iconGoogleMap/" + modulesJSON['modules'][i].profile + "-" + modulesJSON['modules'][i].iconColor + ".png";

            marker = new google.maps.Marker({
            title   : modulesJSON['modules'][i].pseudo,
            //animation: google.maps.Animation.DROP, //BOUNCE
            position: LatitudeAndLongitudeModules,
            map     : Tracking.mapy,
            icon : image
            });

            Tracking.mapBounds.extend(LatitudeAndLongitudeModules);
            Tracking.markers.push(marker);

        };

顺便说一句,有没有办法创建一个按钮,我可以从中手动刷新地图?

4

0 回答 0