I have a geolocation code, but chrome does not give me permission to run it

2

I'd like to know, your I have to give some sort of permission, for the code to work on Chrome, because in Mozilla it can give me the location. Follow the code below '

function writeAddressName(latLng) {
    var geocoder = new google.maps.Geocoder();
    geocoder.geocode({
    "location": latLng

    },
    function(results, status) {
      if (status == google.maps.GeocoderStatus.OK)
        document.getElementById("address").innerHTML = results[0].formatted_address;
      else
        document.getElementById("error").innerHTML += "Unable to retrieve your address" + "<br />";
    });
  }



  function geolocationSuccess(position) {
    var userLatLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
    // Escreva o endereço da localização
    writeAddressName(userLatLng);





    // Coloque o marcador na posição do usuario
      new google.maps.Marker({
      map: map,
      icon:'img/aqui',
      position: userLatLng

    });


    // Desenhe um círculo em torno da posição do usuário para ter uma idéia da precisão de localização atual
    var circle = new google.maps.Circle({
      center: userLatLng,
      radius: 500,
      map: map,
      fillColor: '#0000FF',
      fillOpacity: 0.3,
      strokeColor: '#0000FF',
      strokeOpacity: 1.0,


    });
    map.fitBounds(circle.getBounds());
  }

  function geolocationError(positionError) {
    document.getElementById("error").innerHTML += "Error: " + positionError.message + "<br />";
  }

  function geolocateUser() {
    // Verifica se o navegador suportar a Geolocation API
    if (navigator.geolocation)
    {
      var positionOptions = {
        enableHighAccuracy: true,
        timeout: 10 * 1000 // 10 seconds

      };
      navigator.geolocation.getCurrentPosition(geolocationSuccess, geolocationError, positionOptions);
    }
    else
      document.getElementById("error").innerHTML += "Your browser doesn't support the Geolocation API";
  }

  window.onload = geolocateUser; 
    
asked by anonymous 09.05.2017 / 18:03

1 answer

3

Turning Peter Augustus' comment into answer. Chromium people (the project on which Chrome is based) no longer accept that certain features work over HTTP. You will only be able to use over HTTPS, for security reasons.

Source: link

  

We want to start applying the concepts in link to features that have already shipped and which do not meet the (new, not present at the time) requirements. In particular, this approximately requires access to "secure origins" (such as HTTPS)

Free translation:

  

We want to start applying the concepts in link in the features that have already been released and that do not fit to new requirements (which were not present when features were released). In particular, this means that powerful [sic] features will only be accessible from secure sources (such as HTTPS).

In other words, you will need an SSL certificate on your server to continue using geolocation with Chrome the way you are doing.

    
09.05.2017 / 18:17