In new chrome (44.0.2403.157) geolocations doesnt works

泄露秘密 提交于 2019-11-28 10:06:57

Must be a bug in the latest version of Chrome, also happens in the page of Google Maps API: https://developers.google.com/maps/documentation/javascript/examples/map-geolocation

Hopefully it will be fixed fast.

Edited: Try now, it works :)

Apparently this API has been forbidden access from insecure locations see here

For future queries:

Starting with Chrome 50, Chrome no longer supports obtaining the user’s location using the HTML5 Geolocation API from pages delivered by non-secure connections. This means that the page that’s making the Geolocation API call must be served from a secure context such as HTTPS.

https://developers.google.com/web/updates/2016/04/geolocation-on-secure-contexts-only?hl=en

This will break your web apps on chrome if you're not using HTTPS.

i didn't get any solution for "Returned error code 403" but i found one solution to get current location if google api fails

 if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(function (position) {
            current_location_lat = position.coords.latitude;
            current_location_lon = position.coords.longitude;
           }, function (error) {
//if error occurred by google api
              $.getJSON("http://ipinfo.io", function (ipinfo) {
                var latLong = ipinfo.loc.split(",");
                current_location_lat = latLong[0];
                current_location_lon = latLong[1];
                 });
            });

    } else {
        // Browser doesn't support Geolocation
        alert("Error: Your browser doesn\'t support geolocation");
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!