2016-09-07 11 views
8

मैं एक ऐसा एप्लीकेशन विकसित कर रहा हूं जो भौगोलिक स्थान निर्देशांक का उपयोग करता हो। मैंने साइट विज़िटर के स्थान का पता लगाने के लिए HTML5 भौगोलिक स्थान सुविधा का उपयोग किया, लेकिन समस्या क्रोम के साथ है जो असुरक्षित उत्पत्ति पर भू-स्थान का समर्थन नहीं करती है।एसएसएल कनेक्शन के बिना जिओलोकेशन

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."); 
    } 
} 

यहाँ कोड getCurrentPosition में काम नहीं कर रहा के रूप में अपनी साइट से जुड़ा हुआ एसएसएल नहीं है।

क्रोम द्वारा चेतावनी: getCurrentPosition() और watchPosition() अब असुरक्षित उत्पत्ति पर काम नहीं करते हैं। इस सुविधा का उपयोग करने के लिए, आपको अपने एप्लिकेशन को एक सुरक्षित उत्पत्ति, जैसे HTTPS पर स्विच करने पर विचार करना चाहिए।

क्या क्रोम पर निर्देशांक/लेटलॉन्ग मान प्राप्त करने का कोई अन्य तरीका है? [असुरक्षित कनेक्शन पर केवल]

संपादित: यह स्थानीय होस्ट का उपयोग कर मेरी मशीन में काम कर रहा है: 80 लेकिन परीक्षण यूआरएल जो http पर है में काम नहीं कर

+0

गुगल। लेकिन अच्छा समाधान नहीं मिला। –

+0

स्पष्ट प्रश्न: HTTPS का उपयोग शुरू करना एक विकल्प नहीं है ...? – deceze

+0

एचटीपीएस एक विकल्प है। लेकिन सिर्फ यह जानना चाहता था कि कोई वैकल्पिक –

उत्तर

13
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(); 
+1

अच्छा, मुझे लगता है कि यह काम करता है। –

+1

अद्यतन करने की कोशिश करेगा यह एपीआई कुंजी बदलने के बाद काम किया। –

+0

यह समाधान सटीक निर्देशांक वापस नहीं करता है –

3
यहाँ

सफारी के लिए मेरी गैर एसएसएल समाधान में है

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; 
: 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(); 

नए हिस्से में "मामले error.POSITION_UNAVAILABLE" इस एक है

संबंधित मुद्दे