Http 站点未检测到 Chrome 中的位置 - 问题

我们今天确实注意到了根据用户位置自动检测邮政编码的问题.它在其他浏览器(edge、IE、Firefox)中运行良好我们必须将站点配置为 https,然后它就可以正常工作了

We did notice today an issue in automatic detection of zip code based on the user s location. it worked well in other browsers(edge, IE, Firefox) We had to configure the sites to https and then it works ok

示例:https://www.whatismyzip.com/ 效果很好其中 http://www.mapdevelopers.com/what-is-my-zip-code.php 不起作用.

Example : https://www.whatismyzip.com/ works well where as http://www.mapdevelopers.com/what-is-my-zip-code.php does'nt work.

  <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAdGQKI4sEj5TZAjNCds422V_ZHevD45Fo"></script>
 <%--   <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"></script>--%>

 <%--     <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?libraries=places"></script>
 <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>--%>
    <script type="text/javascript">


        function ShowMessages() {

            debugger;
            if (navigator.geolocation) {
                navigator.geolocation.getCurrentPosition(success);
            } else {
                alert("Geo Location is not supported on your current browser!");
            }
            function success(position) {
                debugger;
                var lat = position.coords.latitude;
                var lng = position.coords.longitude;
                var latlng = new google.maps.LatLng(lat, lng);
                var geocoder = geocoder = new google.maps.Geocoder();
                geocoder.geocode({ 'latLng': latlng }, function (results, status) {
                    if (status == google.maps.GeocoderStatus.OK) {
                        if (results[1]) {

                            var searchAddressComponents = results[0].address_components,
                             searchPostalCode = "";
                            $.each(searchAddressComponents, function () {
                                if (this.types[0] == "postal_code") {
                                    searchPostalCode = this.short_name;
                                }
                            });

                            document.getElementById('hidden1').value = searchPostalCode
                            __doPostBack('', '');


                        }
                    }
                });
            }

        }

任何帮助/解决方法将不胜感激.

Any help/workaround would be appreciated.

除了 Google API,还有其他可行的替代方案吗?

推荐答案

Chrome 50 中引入的新安全规则不会将位置信息发送到没有 Transfer Encryption 的站点.

The new Security rule introduced in Chrome 50 does not send Location Information to Sites without Transfer Encryption.

这里是适合 Mapping API 问题的替代方案.

Here are the alternatives which are apt for the Mapping API problems.

恢复到之前的 Chrome(50) 版本也是一种解决方案,但是在 Web 开发中,这样做是相当困难的.

Reverting to Prior versions of the Chrome(50) is also a solution, but in Web development, it is quite difficult to do so.

但事实是,目前只有 Chrome 与 Mapping API 存在此类问题,其他 浏览器 仍然支持它们(其中让我暂时放心).

But the fact is that, currently only Chrome has such issues with Mapping API and other Browsers still supports them(Which gives me a short term peace of mind).

但迟早,这可能会被其他浏览器实践,这对于与我不同的现有用户来说可能是一个大问题.由于这是一个长期的过程(在我的情况下),最好开始开发和迁移到 https 站点而不是在 http 中,但是有 利弊处理它们.

But sooner or later, this may be practiced by other browsers too, which may be a big problem for the existing users unlike me. Since it is a long term process(in my case), it is better to start developing and migrating to https sites rather than being in http, how ever there are pros and cons in handling them.

相关文章