Why is the centering of my map off in my jQuery Mobile / Google Maps API3 application?

后端 未结 4 1274
情歌与酒
情歌与酒 2020-12-19 10:49

I have a map powered by Google Maps Javascript API3 in my jQuery Mobile web application. I added a circle with black borders on it.

If you go to this page of my app

相关标签:
4条回答
  • 2020-12-19 11:38

    Call google.maps.event.trigger(mapObj, "resize"); on pageshow or pagechange

    0 讨论(0)
  • 2020-12-19 11:41

    Because the page is actully loaded via ajax (when coming from index) - the page event you are using is probably being called before the DOM is totally ready. GMaps expect the page to be ready.

    Try using a different event other than pageinit. Looks like pageshow might be a good one (as it runs after any animation has finished) http://jquerymobile.com/demos/1.0/docs/api/events.html

    Or maybe you could put the call to the maps resize event, in a pageshow event.

    0 讨论(0)
  • 2020-12-19 11:41

    Is the page reloading between the home page and the map? If not, and if you're creating or resizing a div, you'll need to call google.maps.event.trigger(map, 'resize') after the div changes (size change or removing a display:none). (edited to show the code to trigger the event, thanks to @Heitor Chang)

    0 讨论(0)
  • 2020-12-19 11:46

    In my case, my workaround is $('#mapdiv').trigger('create'); working well. but in other cases I don't know it works.

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