0

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!

Sindre
  • 3,880
  • 2
  • 26
  • 39

1 Answers1

0

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..

Deepak Kumar
  • 672
  • 4
  • 15
  • 31
  • Yes, that is spot on! It's being called inside the $(function(){..} which is not fired on the page change from the footer menu. But whats weird is that is not fired on navigation either. Any suggestions? – Sindre Feb 03 '12 at 12:25
  • try to call it just before your body tag closed. I mean just before

    .

    – Deepak Kumar Feb 03 '12 at 12:28
  • It seems that no javascript gets run at all. in head or just before – Sindre Feb 03 '12 at 12:36
  • Ah, here we go. For anyone with a similar problem: http://jquerymobile.com/test/docs/pages/page-scripting.html – Sindre Feb 03 '12 at 12:42
  • your link to the site is not working. Can you double check that NO ERROR is being generated in the error console? – Deepak Kumar Feb 03 '12 at 12:45
  • Link was probably not working because I was updating it :-) jQuery Mobile strips styles and scripts from the header of linked pages when getting through ajax (which was on in my case). But it will execute site spesific style and script if put just before the last end-div on the FIRST page.
    – Sindre Feb 03 '12 at 14:03