My Google Map javascript code displays on desktop browser but not my mobile phone browser

前端 未结 1 855
悲&欢浪女
悲&欢浪女 2021-01-07 02:59

Okay, so I already looked this up and only found one page on it.

(Google Maps API GeoLocation not working for mobile)

My issue is that that I have some javas

相关标签:
1条回答
  • 2021-01-07 03:35

    You made a few mistakes. I updated your code and added comments for an explanation: http://jsfiddle.net/cj5xF/1/

    There's also a fullscreen view (test on mobile): http://jsfiddle.net/cj5xF/1/embedded/result/

    Snippet from the fixed code:

        // When the page has loaded, call the getLocation function.
        // Be sure not to use parenthesis after getLocation, or you will
        // call it, instead of passing a reference to it to be called later (callback)
        google.maps.event.addDomListener(window, 'load', getLocation);
    

    This will call the getLocation function when the page has loaded. The getLocation function will perform its geolocation checks, and if available, call initialize and pass into it the position object, which contains coordinates. initialize will then use those coords to create a google map.

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