I have this problem with Google Places API. I'm searching for "Guildhall" in Cambridge. It finds it exactly on maps: https://www.google.pl/maps/place/Guildhall,+Market+Hill,+Cambridge+CB2+3QJ,+Wielka+Brytania/#52.2046916,0.1193167,17z/data=!3m1!4b1!4m2!3m1!1s0x47d870bd9c1c0a5d:0x7228336bd9005dae
But places api doesn't return "Guildhall" as a result: https://maps.googleapis.com/maps/api/place/search/json?location=52.2046916,0.1193167&rankby=distance&keyword=guildhall&sensor=true&key=YOUR_API_KEY
Is it possible to return results like "Guildhall" from Places API?
You can configure the types of places you want returned by specifying the type:
See the documentation here; https://developers.google.com/places/documentation/supported_types
Then pass in the type option when creating your service;
var request = {
location: pyrmont,
radius: '500',
types: ['store'] // specify the types here
};
service = new google.maps.places.PlacesService(map);
service.nearbySearch(request, callback);
UPDATE:
I may have a solution for you: You could try using the Geocode service from Google: https://developers.google.com/maps/documentation/javascript/examples/geocoding-simple
I have put it into a JS Fiddle for you to have a playaround with: http://jsfiddle.net/loanburger/1vhymg6m/
Hope that helps
Related
I'm making a call to get multiple routes from google maps Distance Service API and I'm able to get a successful response. But I want to get the route URL (shortURL), so if the client clicks on the link he'll be directly redirected to google maps showing the route. Here is my code:
var directionsService = new google.maps.DirectionsService;
return directionsService.route({
origin: origin,
destination: destination,
travelMode: 'DRIVING',
provideRouteAlternatives: true,
unitSystem: google.maps.UnitSystem.IMPERIAL,
}, shortestRoute);
If you are not trying to use the Google Maps Directions Service for navigation purposes, what you could do instead is dynamically supply the (shortURL) based on user input assuming you are listening to user input on your side of the application.
One simple implementation is that you provide the (shortURL) right off the bat so that users may type the Directions information on the actual Google Maps page instead of on your site assuming you are not loading a modal and/or iframe since you mentioned redirecting.
Now if you are not planning on redirecting before the user inputs their data. You could setup something like:
See Documentation.
var origin;
// This function gets called when you are ready to submit the user's input.
function directionsOrigin(){
var origin = document.getElementById('origin-input').value;
placeholdDynamicInput(origin);
}
function placeholdDynamicInput(origin, dynamicUrl){
// Following this
// protocol-> https://www.google.com/maps/dir/?api=1¶meters
var url = 'https://www.google.com/maps/dir/?api=1&origin=' + origin;
// Dynamically create your placeholder URL using user input.
}
function dynamicUrl(){
// Handle this function however makes sense with your application
}
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 am plotting a map using south african addresses. This in general works fine but in some instances the API seems unable to find the address and returns the same lat/lng plotted in the centre of the country. I am using the following function to retrieve the coordinates:
function getpointfromaddress(location, callbackfunction){
var geocoderRequest = { address: location, componentRestrictions: {country: 'ZA'} };
geocoder.geocode(geocoderRequest, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var point = results[0].geometry.location
callbackfunction(point)
}
})
}
An example of an address that won't map is "Corner of Witkoppen & Nanyuki Rd,Sunninghill Park,Sandton,2199". The address maps fine using google maps online.
Many thanks for any help you can give.
The problem could be because of the '&' in your address. Calling the address directly from google maps generates the following link.
https://www.google.co.in/maps/search/Corner+of+Witkoppen+%26+Nanyuki+Rd,Sunninghill+Park,Sandton,2199/#-26.029296,28.0215236,14z/data=!3m1!4b1
The '&' is replaced with '%26' in the query.
You can accomplish this in your program by URL encoding the address or by replacing it programmatically in Javascript.
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