阻止Google地理编码使用语音搜索

时间:2016-03-03 17:11:44

标签: javascript google-maps google-geocoder phonetics

我正在使用Google地理编码来获取城市(例如伦敦)数据,例如经度/纬度/州/国家/等等,但当我使用搜索短语“Lindon”而不是“伦敦”时,它仍会找到并返回伦敦的数据。有没有办法关闭谷歌地理编码的语音搜索?

在www.okcupid.com的注册页面上测试,当我输入'Lindon'时找不到任何内容,这就是我想要的。也许他们没有使用谷歌地理编码???

enter image description here

以下是我的地理编码代码示例

function getAddressInfoBySearch(address) {
  if (address.length < 40 && typeof google != 'undefined') {
    var addr = {};
    var geocoder = new google.maps.Geocoder();
    geocoder.geocode({
      'address': address
    }, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        if (results.length >= 1) {
          for (var ii = 0; ii < results[0].address_components.length; ii++) {
            var street_number = route = street = city = state = zipcode = country = formatted_address = '';
            var types = results[0].address_components[ii].types.join(",");
            if (types == "street_number") {
              addr.street_number = results[0].address_components[ii].long_name;
            }
            if (types == "route" || types == "point_of_interest,establishment") {
              addr.route = results[0].address_components[ii].long_name;
            }
            if (types == "sublocality,political" || types == "locality,political" || types == "neighborhood,political" || types == "administrative_area_level_3,political") {
              addr.city = (city == '' || types == "locality,political") ? results[0].address_components[ii].long_name : city;
            }
            if (types == "administrative_area_level_1,political") {
              addr.state = results[0].address_components[ii].short_name;
            }
            if (types == "postal_code" || types == "postal_code_prefix,postal_code") {
              addr.zipcode = results[0].address_components[ii].long_name;
            }
            if (types == "country,political") {
              addr.country = results[0].address_components[ii].long_name;
            }
          }
          addr.success = true;
          //for (name in addr) {
          //    console.log('### google maps api ### ' + name + ': ' + addr[name]);
          //}
          response(addr);
        } else {
          response({
            success: false
          });
        }
      } else {
        response({
          success: false
        });
      }
    });
  } else {
    response({
      success: false
    });
  }
};

0 个答案:

没有答案