jQuery-ui-map not displayed when navigating from other html file

1.2k views Asked by At

This is my first question on stackoverflow, so be gentle :)

I'm making a mobile web application with jQuery, jQuery mobile and the jQuery-ui-map plugin. The map works perfectly when I refresh the file where it should be displayed (map.html), but when navigating from index.html it doesn't turn up at all. Console show no erros. I've tried doing a $('#map_canvas').gmap('refresh'); on pageinit, but that doesn't work either. Also that messes up the panning when I refresh the file directly...

I've also tried without the prefetching in the footer menu and with data-rel="external" (that messed up the jquery mobile styling)

Here is the footer navigation from index.html:

     <div data-role="footer" data-theme="a" data-position="fixed">
        <div data-role="navbar">
            <ul>
                <li><a data-transition="fade" class="txt_footer_href_home ui-btn-active" href="index.html" data-prefetch>Home</a></li>
                <li><a data-transition="fade" class="txt_footer_href_offers" href="offers.html" data-prefetch>Offers</a></li>
                <li><a data-transition="fade" class="txt_footer_href_store" href="store.html" data-prefetch>Store</a></li>
                <li><a data-transition="fade" class="txt_footer_href_map" href="map.html" data-prefetch>Map</a></li>
                <li><a data-transition="fade" class="txt_footer_href_more" href="more.html" data-prefetch>...</a></li>
            </ul>       
       </div>
    </div>

And here is the code for the map:

$('#map_canvas').gmap({'maxZoom':17,'center': new google.maps.LatLng(center_latitude,center_longitude),'callback': function() {
    var self = this;
    // Get the current position
    self.getCurrentPosition(function(position, status) {
        // If we got the current position, add the marker
        if ( status === 'OK' ) {
            // Stor current position in a var
            var clientPosition = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
            // Add the current position marker
            self.addMarker({ id:'mark_pos','position': clientPosition, 'bounds': true})
            .click(function() {
                $('#map_canvas').gmap('openInfoWindow', { 'content': Lang.mapHtml.txt_marker_my_position_content }, this);
            });
            // Paint a blue cirecle where your position is
            self.addShape('Circle', { 
                'strokeWeight': 0, 
                'fillColor': "#008595", 
                'fillOpacity': 0.25, 
                'center': clientPosition, 
                'radius': 15, 
                'clickable': false 
            });
            // Bind direction marker button and show it
            $("#divBtnDirection").show();
            var that = this;
            $("#btn_directions").click(function() {
                that.displayDirections({ 'origin': clientPosition, 'destination':center_latitude+','+center_longitude , 'travelMode': google.maps.DirectionsTravelMode.DRIVING }, { 'panel': document.getElementById('directions') }, function(result, status) {
                if ( status === 'OK' ) {
                    $('#map_canvas').gmap('clear', 'markers');
                    $("#divBtnDirection").hide();
                    $("#directions").fadeIn(1000);

                }
            });  

            });             
    }
        // Add the shopping centers marker

    self.addMarker( { id:'mark_center', 'position': center_latitude+','+center_longitude, 'bounds': true }).click(function() {
                $('#map_canvas').gmap('openInfoWindow', { 'content': Lang.mapHtml.txt_marker_center_content }, this);
            });
    });   


}});

The site is currently being displayed here (its in Norwegian)

Thank you!

1

There are 1 answers

6
Deepak Kumar On BEST ANSWER

First of all Welcome to Stackoverflow..:) Make sure your function is being called while navigating. Try to put a messagebox in the function and check.

And also try putting a call to map function in head section of your

$(function(){
//your function call
});

Hope this helps..