开发者

maps displayed wrong on mobile (using JQuery mobile)

开发者 https://www.devze.com 2023-03-28 11:26 出处:网络
I\'m using jQuery mobile and I have to display some maps. I\'m using a function that create maps every time that I click on the specific link but after the generation of the first map, the others are

I'm using jQuery mobile and I have to display some maps. I'm using a function that create maps every time that I click on the specific link but after the generation of the first map, the others are displayed wrong.

Here an example, First map:

maps displayed wrong on mobile (using JQuery mobile)

Other maps:

maps displayed wrong on mobile (using JQuery mobile)

I use a function like this:

function buildMap(div){

    var coord = new google.maps.LatLng(lat, lng);

    var options = {
        zoom: 13,
        scrollwheel: false,
        scaleControl: true,
        mapTypeControl: false,
        center: coord,
        mapTypeId: google.maps.MapTypeId.HYBRID
    };

    var map = new google.maps开发者_StackOverflow.Map(div, options);

    return map;
}

Can you help me?

Thank you!!


Problem solved, you need to create the map on the "pageshow" event (an event of jQuery mobile):

$('#map_page').live('pageshow',function(event, ui){
    buildResultMap('#map_canvas');
});


The solution is to trigger the resize event OR not to use Ajax. Phill has guided you to an example how it's done with the jQuery Mobile Google maps plugin which uses Ajax (and calls $('#map_canvas').gmap('refresh'); on pageload. The plugin is very easy to use (especially if you already know Google maps syntax).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号