navigator.geolocation.getCurrentPosition doesn't work on android google chrome

后端 未结 7 1870
醉酒成梦
醉酒成梦 2021-01-01 10:55

This code:

navigator.geolocation.getCurrentPosition(
                    function(position) {
                        alert(position.coords.latitude, positio         


        
相关标签:
7条回答
  • 2021-01-01 11:24

    THERE IS A WORKAROUND: to watchPosition call, and wrapping this in a 5 second wait before clearing the watchID. Code below;

    var options = { enableHighAccuracy: true, maximumAge: 100, timeout: 60000 };
    if( navigator.geolocation) {
       var watchID = navigator.geolocation.watchPosition( gotPos, gotErr, options );
       var timeout = setTimeout( function() { navigator.geolocation.clearWatch( watchID ); }, 5000 );
    } else {
       gotErr();
    }
    

    I haven't played around with the "options" values or the timeout delay at the moment, but the above code brings back accurate positioning info on every platform I've tried.

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