問題描述
我們今天確實注意到了根據用戶位置自動檢測郵政編碼的問題.它在其他瀏覽器(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.
這篇關于Http 站點未檢測到 Chrome 中的位置 - 問題的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!