错误:网址位置提供商位于&https://www.googleapis.com/' :返回错误代码400

时间:2017-07-02 20:43:30

标签: javascript geolocation

每当我使用400时出现Visual Studio Code错误,但当我使用Brackets时,它的工作正常。

导致此错误的原因是什么?如何解决?

提前谢谢你:)

 <script>
    var watcher;
    var geoLocator;
    window.onload = function() {
        geoLocator = window.navigator.geolocation;
        var posOptions = {
            enableHighAccuracy: true,
            timeout: 45000
        };
        watcher = geoLocator.watchPosition(successPosition, errorPosition, posOptions);
    }

    function successPosition(pos) {
        var sp = document.createElement("p");
        sp.innerText = "Latitude: " + pos.coords.latitude + " Longitude: " + pos.coords.longitude;
        document.getElementById("geoResults").appendChild(sp);
        geoLocator.clearWatch(watcher);
    }

    function errorPosition(err) {
        var sp = document.createElement("p");
        sp.innerText = "error: " + err.message; + " code:" + err.code;
        document.getElementById("geoResults").appendChild(sp);

    }
</script>

0 个答案:

没有答案