Http网站无法检测到Chrome中的位置 - 问题 [英] Http sites does not detect the location in Chrome - issue

查看:71
本文介绍了Http网站无法检测到Chrome中的位置 - 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们今天注意到了一个根据用户位置自动检测邮政编码的问题。它在其他浏览器(边缘,IE,Firefox)中运行良好
我们必须将网站配置为https,然后才能正常工作。

例如: https://www.whatismyzip.com/ 效果良好
其中as http://www.mapdevelopers.com/what-is-my-zip-code.php 'nt work。

 < script type =text / javascriptsrc =https://maps.googleapis.com /地图/ API / JS键= AIzaSyAdGQKI4sEj5TZAjNCds422V_ZHevD45Fo>?< /脚本> 
<% - < script type =text / javascriptsrc =https://maps.googleapis.com/maps/api/js?sensor=false&libraries=places>< /脚本> - %GT;

<% - < script type =text / javascriptsrc =https://maps.googleapis.com/maps/api/js?libraries=places>< /脚本>
< script type =text / javascriptsrc =https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js>< / script> - %GT;
< script type =text / javascript>


函数ShowMessages(){

调试器;
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(success);
} else {
alert(当前浏览器不支持地理位置!);
}
函数成功(位置){
调试器;
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('','');

$ b}
}
});
}

}

任何帮助/解决方法。



编辑:除了Google API之外,还有其他工作方式吗? Chrome 50 中引入的新安全规则不会向没有转移加密的网站发送位置信息 / code>。



这里是适用于Mapping API问题的替代方案。



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



但事实是,目前只有 Chrome Mapping API 和其他浏览器中存在此类问题,仍然支持(其中给我一个短暂的安心)

但其他浏览器迟早也会这样做,这对于现有的用户来说可能是一个大问题,与我不同。由于这是一个长期的过程(在我的情况下),最好开始开发和迁移到https站点,而不是在http中,那么如何优点和缺点。

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

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.

EDIT: Other than Google API, are there any other working alternatives?

解决方案

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

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

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

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).

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.

这篇关于Http网站无法检测到Chrome中的位置 - 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆