Google maps warning: getCurrentPosition() and watchPosition() no longer work on insecure Origins

Asked

Viewed 237 times

0

I’m using Windows with a virtualhost and I need to make the map work on the localhost, only I already have the google key and even so, without putting the appropriate restrictions on the key still appears the message. How do I get the map to work in the localhost environment? Follow the location code that shows the message:

if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
    var pos = {
        lat: position.coords.latitude,
        lng: position.coords.longitude
    };

    infoWindow.setPosition(pos);
    infoWindow.setContent('Esta é a sua localização.');
    map.setCenter(pos);
}, function () {
    handleLocationError(true, infoWindow, map.getCenter());
});
} else {
    // Browser não suporta localização
    handleLocationError(false, infoWindow, map.getCenter());
}
  • you released the localhost url in the google api console?

  • How do you do that?

  • Accesses https://console.developers.google.com, within the Credentials tab you click on the generated credential and add localhost as a trusted test URL!

  • But there are only key restriction options

1 answer

1

  • But no way to work on localhost? I’m using a virtualhost like: store.teste.com. Then I’ll have to play the system online and register a certificate?

  • @Felipemichaeldafonseca You can create a self-signed Certification and use locally on your machine.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.