Getting accurate results from Google Places Library - javascript

I'm using the Places Library to search any type of nearby places by keyword within a LatLngBounds rectangle.
For example if I search for pancakes I'll get restaurants with pancakes on their menu but it will also throw in an establishment with no relation like a juice bar.
How can I get the most accurate results by providing only a keyword? My nearby search request looks like this:
var request = {
bounds: my_bounds, //The bounds within which to search for places
keyword: document.getElementById("keyword").value,
rankBy: google.maps.places.RankBy.PROMINENCE
};
I know that I can also specify a type in the request but that means that the user will have to choose an option from a list of types and I wish to keep search options as minimal as possible. Any kind advice is welcomed!

I am really being selfish here and trying to find an answer to my post - but this question may be related and someone may be able to shine some more light on it for both of us.
I have noticed on a normal Google maps search (i.e. manually in a browser) if I search for: xxxxxx loc: yyyyyyyyyy where xxxxxx is a category such as "university" and yyyyyyyyyy (note the key "loc:" - for location in the middle) is the address I want to search around I get pretty accurate results. I just tested on "pancakes" and same thing. Also many of the sites have a "Category" which lists "pancakes" (or "university") that seems to show a closer match to what is wanted and/or that could be filtered on - better than using "type" or "name". This search also give distance to - which I want but which may not be important to you.
If anyone knows how to do such a "loc:" based search from the APIs that might be the answer to our questions (or maybe just mine)?

Related

How to get only street/road coordinates via reverse geocoding (Google Maps API)

I'm looking for a solution to get data to create a simple roads-only map.
Within a small area specified by lat/long I need data that allows me to draw custom lines between given street coordinates (start and endpoints are basically enough and only from major streets). Coordinates from intersections are also fine to connect those with my custom lines.
Another approaches would be to get all the major street names within the specified area via reverse geocoding and then - somehow - get coordinates for each of this streets.
There was a similar request a couple years ago:
Get street graph for a game using Google Maps API and I'm wondering is it still a big deal to achieve this kind of technical information in a simple way?
EDIT:
I researched the topic but no result gave me the satisfaction I was looking for. For instance Google's Directions/Roads API are both depending on routes. OSM/Google Maps API are filled with information around a specified geo location but without any technical data I need. To be simple: An Array of intersection/street-point coordinates (are they even called coordinates?!).
I think I'm lost - or even stuck - in terms of my own search phrases. I'm not looking for a copy & paste snippet more like a direction or some hints where to focus next or how it is done.
With the clarification of geocodezip's comment I've found the following related question:
How to get all roads around a given location in OpenStreetMap?
This fully suits my demand to get specific road information within a certain location using OSM instead of Google Maps API.
Many thanks

maps.google Geocoding Jquery calls with country codes

Im trying to get a simple geo-location type address lookup thing going using the google maps geocode API using jQuery $.getJSON method.
US & UK postal/zip codes are working fine but i've come across random countries where I'm guessing zip address are the same as other countries and i need to be able to return the correct address.
Im using a select option for someone to pick their country which contains its code e.g. Afghanistan has AF tied to it however when i try pass in the country code I'm still getting the wrong results.
Is there a proper way to call the API or are the results just hit and miss.
Sample below :
Zip for Kabul,Chahar Asyab is 1051
http://maps.googleapis.com/maps/api/geocode/json?address=1051&sensor=false
Will return addresses for Sweden,Slovakia and others countries but the one i want, I've looked briefly at the documentation and someone suggested region parameter in the URL however even with region=afit still returns different results.
Probably an easy fix but i've not found anything yet, i appreciate any help.
Thanks
Found a solution using
components=country:AF as a work around although the data is not always complete but works

How to find a list of visible transit stations

How can I get a list of all transit stations currently on a map, of which the icons are actually visible?
I've tried doing this with the Places API, but the Places API has a couple of fundamental flaws that cannot be worked around:
It can (and does) return multiple places in almost ("almost" is the
problem) the exact same location, one in English and the other in
the local language, but with no way to tell which is which.
It doesn't and cannot know about the map's zoom level. Therefor is will
happily return places that aren't visible on the map when the zoom
level is low enough.
The most likely candidate for returning
anything usable, is the Radar Search. Problem is, the radar search
doesn't return even the name of places. So even a hover on any
returned place must do an additional call, adding to the daily limit
very quickly. The Nearby Search is another candidate, and while it
returns more data per place, it returns fewer places per "page",
requiring many requests after each pan/zoom....
So, the Places API looks very promising, but fails to deliver on the details.
Google Maps, the website, has somehow solved this. Not with the Places API, unsurprizingly, but with something else. It's doing a lot of very weird requests to a url that is undocumented. And the result too seems like they're making it very hard for themselves to parse it. Nevertheless, it seems like it's what I need. Or something like it.
Here's a test case that proves the Places API isn't good enough. Just pan around, zoom in/out and you'll see it failing.
http://home.thany.nl/apps/MYMaps/test2.html

Alternatives to Googles Distance Matrix service?

I am working on a quote calculator that will generate a quote based on mileage between various locations (amongst other conditionals). Up until two days ago, I had planned to use Google's Distance Matrix service until I discovered:
Display of a Google Map
Use of the Distance Matrix service must relate to the display of information on a Google Map; for example, to determine origin-destination pairs that fall within a specific driving time from one another, before requesting and displaying those destinations on a map. Use of the service in an application that doesn't display a Google map is prohibited.
I had hoped to use only the services that I require:
- Distance by Road Measurement between up to three different locations
- Address Autocomplete Service usable on an input box
- Accurate, reliable service that can provide multiple different routes to create an average distance
I know there are other methods available for this, but I doubt many can be as accurate and reliable as Google, I've found it challenging to find anything comparable to Google Maps for the purposes I require.
So, unless you guys can point me to something that I can use, my only option is to use a Google Map where I don't need it, adding additional loading time and altering the UX design I had planned.
Are there any free services available for what I require (preferably with a JS API)?
On a slightly different note
If I do use a Google map, would it have to be displayed immediately, or could I hide it and add an option to 'Show On Map', and have it .slideToggle revealed?
Unfortunately for the Distance Matrix API, Google strictly says you NEED to display the map in your application:
Use of the Distance Matrix API must relate to the display of information on a Google Map; for example, to determine origin-destination pairs that fall within a specific driving time from one another, before requesting and displaying those destinations on a map. Use of the service in an application that doesn't display a Google map is prohibited.
http://developers.google.com/maps/documentation/distancematrix/#Limits
However, what I think is more useful for your need is Google Directions API. The directions API allows you to cover your requirements.
The total distance is returned in the JSON object from the request.
You can select upto as many different locations to find distances between using the Waypoints in your search request. The distances between these locations are then returned in each "leg".
You can obtain the average distance from multiple different routes to your destination by specifying the alternatives parameter in your search request to true. See: http://developers.google.com/maps/documentation/directions/#RequestParameters
Best of all, there is no requirement from Google to display the Google Map in your application when using this service.
I should also mention the drawbacks to this service, if you choose to use it.
The request time it takes to process your request will be slightly longer than if you were to use the Distance Matrix API.
You'll have a lot of unneeded data in the return object, for instance the individual "steps" of the route in the returned json object is not necessary based on your application requirements.
Given the drawbacks, I'd still highly recommend looking into the Directions API for your application.
I don't know if Google Static Maps count as a map, but it should, since it's a Map and from Google.
You could calculate the route and then show it as an image from Static Maps. No extra map loading times required. Only one image.
https://developers.google.com/maps/documentation/staticmaps/#Paths
Many developers have been able to do this with the Bing Maps REST routing service http://msdn.microsoft.com/en-us/library/ff701705.aspx. It requires a bit more development but works well. Here is an example: http://code.msdn.microsoft.com/Bing-Maps-trip-optimizer-c4e037f7
Streetmap and arcserver can solve a vehicle routing problem but it's not free. Read more here: http://www.esri.com/data/streetmap.

Google Map Location constructor with general location type

I have been using Google maps api to get customer to a specific location using a constructor like this
new google.maps.LatLng(42.999, 54.000);
With the exact longitude and latitude as the arguments. What I want to do now is not use the lat, long option and use a keyword like rest area that would bring up the closet rest area. I am not quite finding it in Google map api here https://developers.google.com/maps/documentation/javascript/reference
Can some one help me come up with a constrctor that can take a key word and locate the nearest one in googLe maps.
You're going to have to use the google geocoding API.
Basically you do a request to google with a search string and it returns an object containing the long/lat for areas it may have found... There's a lot of options in there and you can do fairly neat tricks which are already carefully explained by google themselves.
https://developers.google.com/maps/documentation/geocoding/
There are some limitations to the # of requests you can make per-day. To keep this to a minimum you can ofcourse make a server side script that pre-fetches results for things that will be re-used (for example the long/lat for office location of a large enterprise which may have a dot on a map on the website...).
Simplest way would be to make a json request with a few parameters and parse the return json in js, like getting the long/lat of the first result returned.
If I understand correctly, you want to use keyword search for things around a particular location. I would suggest using the Places library of the Google Maps API:
https://developers.google.com/maps/documentation/javascript/places#place_searches
This allows you to search by category or by keyword over Google's datastore of 10s of millions of Places.

Categories

Resources