为本地Firefox调试启用HTTP地理位置

BFa*_*con 12 javascript firefox jquery geolocation

"地理定位请求只能在安全的上下文中完成"

地理定位需要HTTPS,但我需要在不安全的本地服务器上进行调试才能生存.

我希望我可以编辑Firefox的'about:config'来禁用这个安全保护进行调试.我该怎么做?在不安全的上下文中是否有其他/更好的方法来调试位置?(模拟https)

小智 1

我想知道为什么它仍然对我有用,但这是我的代码:

    function geolocate() {
      if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(
            function(position) {
                let lat = position.coords.latitude;
                let lng = position.coords.longitude;
                var geolocation = {
                    lat: lat,
                    lng: lng
                };
                document.getElementById('lat').value = lat;
                document.getElementById('lng').value = lng;
                console.log("----------------------------------------------");
                console.log("Found Location: "+ lat + " / " + lng);

                var google_maps_geocoder = new google.maps.Geocoder();
                google_maps_geocoder.geocode(
                    { 'latLng': geolocation },
                    function( results, status ) {
                        let street = results[0].address_components[1].long_name;
                        let number = results[0].address_components[0].long_name;
                        let plz = results[0].address_components[6].long_name;
                        let city = results[3].address_components[0].long_name;
                        //let country = results[7].formatted_address;
                        let full = street+" "+number+", "+plz+" "+city;

                        // write the values in the fields
                        document.getElementById('autocomplete').value = full;
                        document.getElementById('route').value = street;
                        document.getElementById('street_number').value = number;
                        document.getElementById('postal_code').value = plz;
                        document.getElementById('locality').value = city;
                        //document.getElementById('country').value = country;
                        console.log("User Address: "+street+" "+number+", "+plz+" "+city);
                        $.ajax({
                            type: 'POST',
                            url: 'include/set-location.inc.php',
                            data: {lat: lat, lng: lng, street: street, number: number, plz: plz, city: city, full: full},
                            dataType: 'json',
                            success: function(response) {
                                if(response.status === 'success') {
                                    console.log("Saved address in a cookie!");
                                    if (site === "jobs") {
                                        location.reload(true);
                                    }
                                }
                            }
                        });
                    }
                );
            });
      }
    }
Run Code Online (Sandbox Code Playgroud)

浏览器“问题”: 浏览器“问题”:

我的控制台: 在此输入图像描述

我希望我的代码能帮助你;)