0

I'm using Google geocode to fetch city (ex. London) data like longitude/latitude/state/country/etc, but when I use the search phrase 'Lindon' instead of 'London' it still finds and returns the data for London. Is there a way to turn off phonetic search for google geocode?

Testing this on www.okcupid.com's register page, when I type in 'Lindon' is doesn't find anything, which is what I want. Maybe they aren't using Google geocode???

enter image description here

Here is a sample of my geocode code

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
    });
  }
};
chuckd
  • 13,460
  • 29
  • 152
  • 331
  • The spelling correction feature is implemented in Google's server, and there is no way to turn off it. You can use another geocoder services (not Google) or have the city name dictionary by yourself. – wf9a5m75 Mar 03 '16 at 18:11
  • do you know where I can get a city name dictionary? also what I think I might try is to add more parameters to the search. Like region, that might help elliminate bad searches. ex. London Germany, won't return anything, but London United Kindom will. – chuckd Mar 03 '16 at 18:21
  • There are two parameters, [region and componentRestrictions](https://developers.google.com/maps/documentation/javascript/3.exp/reference#GeocoderRequest), for restricting area. Another tip is adding a zip code or country name when do geocoding. I mean not just "londen", add country name "londen, United Kingdom". – wf9a5m75 Mar 03 '16 at 18:32
  • yes, those two parameters look good. I will try them. one question - what do I use for the region? Can I use a string like 'United States' ???? – chuckd Mar 03 '16 at 18:33

0 Answers0