谷歌地图自动完成国家限制IE8错误

时间:2012-06-28 14:22:27

标签: javascript google-maps

我有一个问题,当我尝试将自动完成限制为仅美国时,它在IE8上失败。 到目前为止无法找到任何帮助,所以我很感激。根据用户是否允许我们跟踪他们的位置来执行错误和成功功能。 在IE9上,如果我不允许,它根本不会工作,在IE8上它无论如何都会失败。更新了最新代码(DNRY ...)

   function setupPlacesAutocomplete() {
       if (navigator.geolocation != undefined)
           navigator.geolocation.getCurrentPosition(successFunctionAC, errorFunctionAC);
       else
           errorFunctionAC();
   }
   //refactor this method
   function getFudgedBounds(lat, lng, fudge) {
       return new google.maps.LatLngBounds(new google.maps.LatLng(lat - fudge, lng - fudge), new google.maps.LatLng(lat + fudge, lng + fudge));
   }
   function successFunctionAC(position) {
       var defaultBounds = getFudgedBounds(position.coords.latitude, position.coords.longitude, .2);
       var options = {
           bounds: defaultBounds,
           componentRestrictions: { country: 'us' }
       };
       setAutoComplete(options);
   }
   function errorFunctionAC() {
       var defaultBounds = getFudgedBounds(parseFloat(geoip_latitude()), parseFloat(geoip_longitude()), .2);
       var options = {
           bounds: defaultBounds,
           componentRestrictions: { country: 'us' }
       };
       setAutoComplete(options);
   }
   function setAutoComplete(options) {
       var input1 = document.getElementById('StartSearchTerm');
       var autocomplete1 = new google.maps.places.Autocomplete(input1, options);
       var input2 = document.getElementById('EndSearchTerm');
       var autocomplete2 = new google.maps.places.Autocomplete(input2, options);
       $('.pac-container').css('z-index', 9999);
   }

0 个答案:

没有答案
相关问题