Google Map API v3 off center if reloaded (not the usual 'resize' thing)

前端 未结 4 635
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-17 05:55

I read all the similar questions but mine is slightly different. The first time a JQuery Mobile dialog is displayed, the map loads fine inside the usual map_canvas div, but

相关标签:
4条回答
  • 2020-12-17 06:19

    I Agree with @peter .. You do not need to create map on each pageshow event.. Instead, try this:

    $(document).on("pagebeforechange", function()
    {
        if(mapObj){
            center = mapObj.getCenter();
        }
    });
    $("#mapPage").bind("pageshow", function()
    {
        google.maps.event.trigger(mapObj, "resize");
        if(center)mapObj.setCenter(center);
    });
    
    0 讨论(0)
  • 2020-12-17 06:21

    You don't need to create a new map each time you visit the page. Create the map beforehand, e.g. on pageinit. On pageshow: google.maps.event.trigger(mapObj, "resize");

    0 讨论(0)
  • 2020-12-17 06:24

    After trying everything else, I finally stumbled upon the pageshow event. Calling initializeMap after all the page transitions are done rather than when clicking the button solved the problem:

    $('#dialog-destination-map').live('pageshow',function(event){
        initializeMap(job_id,"map_canvas");
        }
    );
    

    I still wonder how come it was working at the first load then...

    0 讨论(0)
  • 2020-12-17 06:35

    var driverLatLng is being initialized with lat_lng.split(','); which hasn't been declared before.

    0 讨论(0)
提交回复
热议问题