S
S
sashavol2016-05-30 16:53:00
JavaScript
sashavol, 2016-05-30 16:53:00

Is it possible to remove extra places from autocomplete (google geocode)?

Hello.
I made an autocomplete with a request via geocoder using jquery ui. It returns what you need, but how can you limit the displayed places? Remove bridges, shops, etc., only coordinates, city, country are needed. I see in the guides only a country restriction, but it seems that there is no other restriction by other criteria?
Thanks
Code:

var geocoder = new google.maps.Geocoder();

$('#placeProfile').autocomplete({
  // This bit uses the geocoder to fetch address values

  source: function(request, response) {
    console.log(request);
    geocoder.geocode( {'address': request.term, 'componentRestrictions':{
      'country':'RU'
    }}, function(results, status) {
      response($.map(results, function(item) {
          // Get address_components
          for (var i = 0; i < item.address_components.length; i++)
          {
            var addr = item.address_components[i];
            var getCountry, getCountryShort;
            if (addr.types[0] == 'country')
              getCountry = addr.long_name;
              getCountryShort = addr.short_name;
          }
        return {
          label: item.formatted_address,
          profileCity: item.address_components[0].long_name,
          latitude: item.geometry.location.lat(),
          longitude: item.geometry.location.lng(),
          country: getCountry,
          countrySh: getCountryShort
        }
      }));
    })
  },

  // This bit is executed upon selection of an address
  select: function(event, ui) {
    // Get values
    //$('#profileCountry').val(ui.item.country);
    $('#profileCountrySh').val(ui.item.countrySh);
    $('#profileCity').val(ui.item.profileCity);
    $('#profileLat').val(ui.item.latitude );
    $('#profileLng').val(ui.item.longitude);
  }
});

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question