the secure origin only locatebutton has getcurrentposition fulfilled feature failed error disabled context chrome been html5 geolocation

html5 - secure - navigator geolocation https



Geolocalización Sin conexión SSL (2)

Estoy desarrollando una aplicación que utiliza coordenadas de geolocalización. Utilicé la función de geolocalización de HTML5 para averiguar la ubicación del visitante del sitio, pero el problema es con Chrome, que no es compatible con GeoLocation en orígenes inseguros.

function showPosition(){ if(navigator.geolocation){ navigator.geolocation.getCurrentPosition(function(position){ var positionInfo = "Your current position is (" + "Latitude: " + position.coords.latitude + ", " + "Longitude: " + position.coords.longitude + ")"; document.getElementById("result").innerHTML = positionInfo; }); } else{ alert("Sorry, your browser does not support HTML5 geolocation."); } }

Aquí está el código getCurrentPosition no está funcionando ya que mi sitio no está conectado a SSL.

Advertencia de Chrome: getCurrentPosition () y watchPosition () ya no funcionan en orígenes inseguros. Para utilizar esta función, debería considerar cambiar su aplicación a un origen seguro, como HTTPS.

¿Hay alguna otra forma de obtener coordenadas / valores LatLong en cromo? [en conexión insegura solamente]

EDITAR : Está trabajando en mi máquina usando localhost: 80 pero no funciona en la URL de prueba que está en http


Aquí está mi solución no SSL para Safari en 2017/05

var apiGeolocationSuccess = function(position) { alert("API geolocation success!/n/nlat = " + position.coords.latitude + "/nlng = " + position.coords.longitude); }; var tryAPIGeolocation = function() { jQuery.post( "https://www.googleapis.com/geolocation/v1/geolocate?key=AIzaSyDCa1LUe1vOczX1hO_iGYgyo8p_jYuGOPU", function(success) { apiGeolocationSuccess({coords: {latitude: success.location.lat, longitude: success.location.lng}}); }) .fail(function(err) { alert("API Geolocation error! /n/n"+err); }); }; var browserGeolocationSuccess = function(position) { alert("Browser geolocation success!/n/nlat = " + position.coords.latitude + "/nlng = " + position.coords.longitude); }; var browserGeolocationFail = function(error) { switch (error.code) { case error.TIMEOUT: alert("Browser geolocation error !/n/nTimeout."); break; case error.PERMISSION_DENIED: if(error.message.indexOf("Only secure origins are allowed") == 0) { tryAPIGeolocation(); } break; case error.POSITION_UNAVAILABLE: // dirty hack for safari if(error.message.indexOf("Origin does not have permission to use Geolocation service") == 0) { tryAPIGeolocation(); } else { alert("Browser geolocation error !/n/nPosition unavailable."); } break; } }; var tryGeolocation = function() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition( browserGeolocationSuccess, browserGeolocationFail, {maximumAge: 50000, timeout: 20000, enableHighAccuracy: true}); } }; tryGeolocation();

La parte nueva es esta en "error de caso. POSITION_UNAVAILABLE":

case error.POSITION_UNAVAILABLE: // dirty hack for safari if(error.message.indexOf("Origin does not have permission to use Geolocation service") == 0) { tryAPIGeolocation(); } else { alert("Browser geolocation error !/n/nPosition unavailable."); } break;


var apiGeolocationSuccess = function(position) { alert("API geolocation success!/n/nlat = " + position.coords.latitude + "/nlng = " + position.coords.longitude); }; var tryAPIGeolocation = function() { jQuery.post( "https://www.googleapis.com/geolocation/v1/geolocate?key=AIzaSyDCa1LUe1vOczX1hO_iGYgyo8p_jYuGOPU", function(success) { apiGeolocationSuccess({coords: {latitude: success.location.lat, longitude: success.location.lng}}); }) .fail(function(err) { alert("API Geolocation error! /n/n"+err); }); }; var browserGeolocationSuccess = function(position) { alert("Browser geolocation success!/n/nlat = " + position.coords.latitude + "/nlng = " + position.coords.longitude); }; var browserGeolocationFail = function(error) { switch (error.code) { case error.TIMEOUT: alert("Browser geolocation error !/n/nTimeout."); break; case error.PERMISSION_DENIED: if(error.message.indexOf("Only secure origins are allowed") == 0) { tryAPIGeolocation(); } break; case error.POSITION_UNAVAILABLE: alert("Browser geolocation error !/n/nPosition unavailable."); break; } }; var tryGeolocation = function() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition( browserGeolocationSuccess, browserGeolocationFail, {maximumAge: 50000, timeout: 20000, enableHighAccuracy: true}); } }; tryGeolocation();