Геолокация в IIS 7 без HTTPS - PullRequest
0 голосов
/ 09 июля 2019

Я хочу отобразить полный адрес широты и долготы с геолокацией, но ошибка «Я хочу отобразить полный адрес широты и долготы»

Как заставить работать код

<script src="https://maps.google.com/maps/api/js?key=API_KEY"></script>
<script type="text/javascript"> 
var geocoder;

if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(successFunction, errorFunction);
} 
//Get the latitude and the longitude;
function successFunction(position) {
    var lat = position.coords.latitude;
    var lng = position.coords.longitude;
    codeLatLng(lat, lng)
}

function errorFunction(){
    alert("Geocoder failed");
}

function initialize() {
   geocoder = new google.maps.Geocoder();
}

function codeLatLng(lat, lng) {
    var latlng = new google.maps.LatLng(-6.207861, 106.829444);
    geocoder.geocode({'latLng': latlng}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            console.log(results);
            if (results[1]) {
                var alamat = results[0].formatted_address;
                console.log(alamat);
                document.getElementById("address").value = alamat; 
                //find country name
                for (var i=0; i<results[0].address_components.length; i++) {
                    for (var b=0;b<results[0].address_components[i].types.length;b++) {
                        //there are different types that might hold a city admin_area_lvl_1 usually does in come cases looking for sublocality type will be more appropriate
                        if (results[0].address_components[i].types[b] == "administrative_area_level_1") {
                            //this is the object you are looking for
                            city= results[0].address_components[i];
                            break;
                        }
                    }
                }
            } else {
                alert("No results found");
            }
        } else {
            alert("Geocoder failed due to: " + status);
        }
    });
}

initialize();
</script> 
    <input type="hidden" id="address">
    <?php
        $msg = "<script>var n=document.getElementById('address').value; document.write(n);</script>";
        echo $msg;
    ?>

Я использовал IIS 7 на сервере, но на локальной работе. Пожалуйста, помогите улучшить мой код

...