I want to restrict google to only 'address', '(cities)', '(regions)' et remove commercial market name.
According to the documentation
types
Type: Array
The types of predictions to be returned. Four types are supported: >'establishment' for businesses, 'geocode' for addresses, '(regions)' for >administrative regions and '(cities)' for localities. If nothing is specified, >all types are returned.
But this code return nothing
var options = {
types: ['address', '(cities)', '(regions)']
};
var autocomplete = new google.maps.places.Autocomplete(input, options);
autocomplete.bindTo('bounds', map);
https://jsfiddle.net/7pa4x12L/1/
You're suppose to specify only one type. As Add Autocomplete for places and addresses says:
In general only a single type is allowed.The exception is that you can
safely mix the geocode and establishment types, but note that this
will have the same effect as specifying no types
That's why if you check the sample code from Restrict the search to a specific country you can see that there's only one type specified.
var options = {
types: ['(cities)'],
componentRestrictions: {country: 'fr'}
};
You can see more of this in the Autocomplete sample demo.
Related
I would like to find out what are the companies/businesses around my area of interest. Is there any way that I can download these data (addresses, names) of the companies through google maps?
You may use the google maps' javascript places to do the job. You can use, for example, nearby search witch return you all markets near you. Then, you can specified some names, type of shops, if they are open now...
This is a simply nearby search:
var request = {
location: pyrmont,
radius: '500',
types: ['store']
};
service = new google.maps.places.PlacesService(map);
service.nearbySearch(request, callback);
This is an example of nearby search provided by google.
You also can add the name of the place (the system return you some places with the name that you precise):
var request = {
location: pyrmont,
radius: '500',
types: ['store'],
name: 'Zara'
};
service = new google.maps.places.PlacesService(map);
service.nearbySearch(request, callback);
You may consult the google's documentation.
Tell me if you have some questions.
Note, it is not precise in your question but I use javascript.
Firstly please accept my apologies if this article already exists, but my long search efforts hasn't returned anything useful so far.
I'm integrating Google places autocomplete into one of my website, I'm struggling to find the options that will allow us to sort order the results; Currently we have an issue where a user can input the word London and we want London, UK to be the first results not London road in ...!
We still want the user to be able to search by Road, but we don't want this to show above big cities.
Can anyone please point me in the right direction on how to do this with Google Places Autocomplete?
Unfortunately, changing the order result of the autocomplete is not possible.
The Place Autocomplete service will return candidate matches based on this string and order results based on their perceived relevance.
The closest you can make is to add a restriction by adding type and/or componentRestriction. Currently, you can use componentRestrictions to filter by country.
Sample code:
var input = document.getElementById('searchTextField');
var options = {
types: ['(cities)'],
componentRestrictions: {country: 'fr'}
};
autocomplete = new google.maps.places.Autocomplete(input, options);
You can do something like this
const defaultBounds = new google.maps.LatLngBounds({ lat: 42.5214071, lng: -70.9310135 });
autocomplete = new google.maps.places.Autocomplete(
document.querySelector('#autocomplete'), {types: ['geocode'],
bounds: defaultBounds,
strictBounds: false
});
It will help you more.
I have this options for my autocomplete google map search but when I added the locality and types it wont work.
var options = {
types:['school'],
componentRestrictions: {
locality:'caloocan',
country: 'PH'}
};
Based from this documentation, componentRestrictions can be used to restrict results to specific groups. Currently, you can use componentRestrictions to filter by country. The country must be passed as as a two-character, ISO 3166-1 Alpha-2 compatible country code.
Here is the example from the documentation
var input = document.getElementById('searchTextField');
var options = {
types: ['(cities)'],
componentRestrictions: {country: 'fr'}
};
autocomplete = new google.maps.places.Autocomplete(input, options);
I think the locality part of your code made the errors. Because it is stated in the documentation that "In general only a single type is allowed".
And the (cities) type collection instructs the Places service to
return results that match either locality or administrative_area3
Try to check the parameter that you can use for your code.
I want to only show the cities name using Geocomplete.js. I have restrict the search to only show the cities. But it is still showing the Country name "United State" at the end, i want to get rid from it.
Any Suggestions please
Thanks
Glad that I finally found solution for geocomplete.js! Hope it will be useful to someone.
Solution: Send options with restrictions required to geocomplete function:
var options = {
types: ['(cities)'],
componentRestrictions: {}
};
$("#source").geocomplete(options);
You can also send country-based restrictions.
with Options like
var options = {
types: ['(cities)'],
componentRestrictions: {country: ["usa"]}
};
Google Location Autocomplete using google places api solutions was straightforward and here is the answer
I am having problem with Google places search. If I choose types: ['geocode'] i get no results (ZERO_RESULTS) regardless of a search term. What am i doing wrong? Here is my code snippet:
...
var params = {
name: searchTerm, //search Term is for example 'lon'
bounds: map.getBounds(),
types: ['geocode']
}
var service = new google.maps.places.PlacesService(map);
service.search(params, function (results, status) {
alert(status); - gives ZERO_RESULTS
}
...
Update:
I want it to behave the same as Javascript AOI places Autocomplete. To get me the same results. I thought they are querying the same data?
var input = document.getElementById('location');
var options = {
bounds: map.getBounds(),
types: ['geocode']
};
autocomplete = new google.maps.places.Autocomplete(input, options);
google.maps.event.addListener(autocomplete, 'place_changed', function() {
....
This one gives me great results. ( reason i am not using autocomplete method over first solution is because i could not manage to auto select first item in autocomplete list once enter (in search fields) is hit. - if you know answer to that please help :)
At this time at least, it is best not to assume that Google Places has a lot of data for a location or that the data is finely categorized. It is entirely likely that Google Places has few or no places of type geocode for you to find.
Since types is optional, remove it and you will likely get results.
UPDATE: Regarding the Autocomplete vs. Places Search stuff that has been added to the question: I have not used Autocomplete, but I would think that it should not give you the same results. A Places Search is trying to find stuff that matches search term XXXXX. Autocomplete is trying to predict given substring XXXXXX what it is you may be trying to type. So it is likely to return more (and different, and in many cases less relevant) results. So what you are seeing (more results with Autocomplete) does not strike me as anomalous.
I have found that by removing the "types" parameter I get way more places. I am using places autocomplete and it definately gives me more options without the types.
I am just catching the enter key and stopping it, to prevent users submitting the form accidentally. Not quite what you wanted but it works for me.
$("#LatLongSearch").keypress(function (event) {
if (event.which == 13) { // make enter key just search map and stop it from submitting form
event.preventDefault();
}
})
try this
$('#searchform').keypress(function(e) {
if (e.which == 13) {
e.preventDefault();
google.maps.event.addListener(autocomplete, 'place_changed', function() {
fillInAddress();
$('#yourform').submit();
}); } });
It work for me