Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/428.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何修复。[Deprecation]getCurrentPosition()和watchPosition()不再适用于不安全的源。_Javascript_Jquery_Google Maps_Google Chrome_Maps - Fatal编程技术网

Javascript 如何修复。[Deprecation]getCurrentPosition()和watchPosition()不再适用于不安全的源。

Javascript 如何修复。[Deprecation]getCurrentPosition()和watchPosition()不再适用于不安全的源。,javascript,jquery,google-maps,google-chrome,maps,Javascript,Jquery,Google Maps,Google Chrome,Maps,当我尝试在我的临时服务器[Deprecation]getCurrentPosition和watchPosition中运行代码时,出现了一个控制台错误,该代码不再适用于不安全的源代码。要使用这个特性,您应该考虑将应用程序切换到安全的原点,例如HTTPS.< /P>。 在我的标题中,我正在链接脚本标记 <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBlS6vRUDeM0XdliZ4iWDyDMekH45wYcck&

当我尝试在我的临时服务器[Deprecation]getCurrentPosition和watchPosition中运行代码时,出现了一个控制台错误,该代码不再适用于不安全的源代码。要使用这个特性,您应该考虑将应用程序切换到安全的原点,例如HTTPS.< /P>。 在我的标题中,我正在链接脚本标记

<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBlS6vRUDeM0XdliZ4iWDyDMekH45wYcck&libraries=places" type="text/javascript"></script>
获取您当前的职位: 点击这里

    <p id="demo"></p>

    <script>
    var x = document.getElementById("demo");

    function getLocation() {
      document.getElementById("start").value = "";
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(showPosition);
        } else { 
            x.innerHTML = "Geolocation is not supported by this browser.";
        }
    }

    function showPosition(position) {
        x.innerHTML = "Latitude: " + position.coords.latitude + 
        "<br>Longitude: " + position.coords.longitude;
        document.getElementById('cityLat').value = position.coords.latitude;
        document.getElementById('cityLng').value = position.coords.longitude;
    }
    </script>
    <script type="text/javascript">
var directionDisplay;
var directionsService = new google.maps.DirectionsService();
var map;

function initialize() {
  directionsDisplay = new google.maps.DirectionsRenderer();
  var bangalore = new google.maps.LatLng(12.9716, 77.5946);
  var myOptions = {
    zoom:12,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    center: bangalore
  }

  map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  directionsDisplay.setMap(map);
}

function calcRoute() {
  var startLat = document.getElementById('cityLat').value;
  var startLong = document.getElementById('cityLng').value;

  var endLat = $('select.end').find(':selected').data('lat');
  var endLong = $('select.end').find(':selected').data('long');

  /*alert(startLat+"---"+startLong+"---"+endLat+"---"+endLong);*/

  if(startLat && startLong){
    var start = new google.maps.LatLng(startLat, startLong);
  }else{
    var start = document.getElementById("start").value;
  }

  var end = new google.maps.LatLng(endLat, endLong);

  var distanceInput = document.getElementById("distance");

  var request = {
    origin:start, 
    destination:end,
    travelMode: google.maps.DirectionsTravelMode.DRIVING
  };

  directionsService.route(request, function(response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
      directionsDisplay.setDirections(response);
      distanceInput.value = response.routes[0].legs[0].distance.value / 1000;
    }
  });
}
</script>
当我在本地系统中运行上述代码片段时,我正确地获得了映射

当我将代码移动到测试服务器时,控制台错误[Deprecation]getCurrentPosition和watchPosition不再适用于不安全的源。要使用这个特性,您应该考虑将应用程序切换到安全的原点,例如http:/p> 我尝试了不使用https的脚本标记源链接

谁能给我一个建议吗?
多谢各位

您需要安装SSL证书。此解决方案没有快速修复方法。Google Chrome和其他浏览器出于安全原因正在阻止此操作。

Chrome已禁止在没有SSL的网站上使用getCurrentPosition


Google Maps API可以解决这个问题,但它的使用限制非常低。

这不是您包含的脚本的问题,而是您的域的问题。您必须在HTTPS协议上托管您的web,而不是HTTP。谷歌一点也不喜欢HTTP。可能的重复可能的重复可能的重复可能的重复