We are currently using the google trip planning feature on our transit website. The issue we are running into is the fact that when a customer types in a starting point (for example "Queensway" in Kelowna, BC Canada) we get auto-fill results from all over North America. Can the auto-fill results be restricted to a specific province or state? Thanks!
Try using Component Filtering
In a geocoding response, the Google Maps Geocoding API can return address results restricted to a specific area. The restriction is specified using the components filter. A filter consists of a list of component:value pairs separated by a pipe (|). Only the results that match all the filters will be returned. Filter values support the same methods of spelling correction and partial matching as other geocoding requests. If a geocoding result is a partial match for a component filter it will contain a partial_match field in the response.
The components that can be filtered include:
route matches long or short name of a route.
locality matches against both locality and sublocality types.
administrative_area matches all the administrative_area levels.
postal_code matches postal_code and postal_code_prefix.
country matches a country name or a two letter ISO 3166-1 country code.
Note: Each address component can only be specified either in the address parameter or as a component filter, but not both. Doing so may result in ZERO_RESULTS.
A geocode for "Santa Cruz" with components=country:ES will return Santa Cruz de Tenerife in Canary Islands, Spain. Request:
https://maps.googleapis.com/maps/api/geocode/json?address=santa+cruz&components=country:ES&key=YOUR_API_KEY
See this sample: Place Autocomplete Hotel Search for code implementation.
Hope it helps!
Related
I am using a Google Places API to return ratings for an entered property. When I enter the property name as the search term, a rating is returned, but if I attempt to return a rating by using an address (which is supported by the text input) I do not receive a response. I have tried searching an address through the API, returning a Place ID and then using the Place ID to return a rating, but that does not work.
This API returns a rating: https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=The+Shops+At+Chestnut+Hill&inputtype=textquery&fields=rating&key=[MY API_KEY]
This is the same property, but searched by address, which does not: https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=199+Boylston+St+Chestnut+Hill+MA&inputtype=textquery&fields=rating&key=[MY API_KEY]
Is there something different with the formatting of address inputs I am not doing correctly?
The places API has separate ids for the address/building and the establishment in it. The address/building won't have the rating, the place/establishment will.
From the PlaceId Finder
The Shops at Chestnut Hill
Place ID: ChIJkcWRbZF444kRJUJjXdUFIOw
199 Boylston St
Place ID: ChIJ4TgqFZF444kR2XHKhTgsiNs
(although I do see an entry in the dropdown for the "place" when I enter the address)
The Places API nearbySeach only returns places, not address place ids. The geocoder returns the place_id of the address. But the nearbySearch takes a set of coordinates, not an address, so to get those results from an address requires two calls, one to geocode the address, one to get the nearbySearch results from that location.
Note that there are multiple results at the location of that address (4 exactly at the location returned from geocoding "199 Boylston St Chestnut Hill MA", and 15 other places that are nearby and in the footprint of "The Shops at Chestnut Hill"), more if you use pagination to get more than 20 results.
When using the Nokia Here Geocoding Service the State parameter is ignored when searching by searchText: 315 NE 14th Street, State: FL and Country: US.
The only result returned is a location in Louisiana. Adding the State to the end of the searchText doesn't work either.
Google and MapQuest properly return the result in Florida. The client does not want to include a city but rather an address, state and country.
I know that the Nokia Here algorithm does not filter down a closely as Google and MapQuest but expected that the inclusion of the State parameter would force the result search.
You can try setting a search area, so you can further narrow down the results. The following Android example will return one result in Homestead, Florida City:
String query = "315 NE 14th Street Florida US";
GeocodeRequest geocodeRequest = new GeocodeRequest(query);
GeoCoordinate areaCenterCoordinate = new GeoCoordinate(27.82353, -81.760254);
geocodeRequest.setSearchArea(areaCenterCoordinate , 15000);
According to documentation GeocodeRequest processes text string queries, so I believe you can omit state or country parameters and add state or country as part of the search term. Please note that multiple results can be returned if they all match to the given search term.
An example on how to use GeoCoder can be found here.
Depending on your use case, maybe consider to use SearchRequest instead. If this does not help it would be great if you can provide more details in your question, e.g. what API flavor you are referring to.
We have a program which calls the Google Geocoding API passing an address. we would like to understand for which of the address, the latitude and longitude values are very correct and for which of them it is approximated.
in the response, there are some tags like address_component which can have multiple "type" tag. there is also location_type under 'geometry'-->'location'
There is also 'type' directly 'result'
we are going which the following logic to understand if the lat and long are accurate.
Check for the multiple "type" under "address_components" and if we find either value "route" or "street_number" in any of the type tags, then it is very accurate.. should we use anyother tags from geocoder response like "location_type" under "location" or "type" under "result" tags.
There is some information on Google Geocoding info, but did not figure out if there is a kind of logic we could apply.
Regards
Siva
The location_type tells you the accuracy of that result, partial match tells you the geocoder did not return an exact match for the request.
See the documentation: Results: location_type/partial match
geometry contains the following information:
location contains the geocoded latitude,longitude value. For normal address lookups, this field is typically the most important.
location_type stores additional data about the specified location. The following values are currently supported:
"ROOFTOP" indicates that the returned result is a precise geocode for which we have location information accurate down to street address precision.
"RANGE_INTERPOLATED" indicates that the returned result reflects an approximation (usually on a road) interpolated between two precise points (such as intersections). Interpolated results are generally returned when rooftop geocodes are unavailable for a street address.
"GEOMETRIC_CENTER" indicates that the returned result is the geometric center of a result such as a polyline (for example, a street) or polygon (region).
"APPROXIMATE" indicates that the returned result is approximate.
partial_match indicates that the geocoder did not return an exact match for the original request, though it was able to match part of the requested address. You may wish to examine the original request for misspellings and/or an incomplete address.
Partial matches most often occur for street addresses that do not exist within the locality you pass in the request. Partial matches may also be returned when a request matches two or more locations in the same locality. For example, "21 Henr St, Bristol, UK" will return a partial match for both Henry Street and Henrietta Street. Note that if a request includes a misspelled address component, the geocoding service may suggest an alternative address. Suggestions triggered in this way will also be marked as a partial match.
I am using the Google Maps Places library to do a search for nearby hospitals, but it returns results that aren't necessary hospitals (but have 'hospital' as one of their types). However, I've noticed that actual hospitals have a hospital icon on the map, so Google must somehow know which establishments are actually hospitals. Does anyone know if the public has access to this data?
This is the icon I'm referring to: https://www.dropbox.com/s/1jfqcayxavjhlyi/Screenshot%202015-03-17%2017.20.19.png?dl=0
Example of request I'm making:
var request = {
location: self.location,
radius: 20000,
types: ['hospital'],
keyword: 'hospital'
};
Example result that isn't a hospital:
{"geometry":{"location":{"k":44.815958,"D":-68.808244}},
"icon":"http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png","id":"de6e60bd70b90ba4cb86afe149a60169553607f1",
"name":"Penobscot Community Health Center",
"opening_hours":{"open_now":true,"weekday_text":[]},
"photos":[{"height":320,"html_attributions":[],"width":320}],"place_id":"ChIJj--4INRKrkwRN0z2XkoJtVU",
"rating":3.1,
"reference":"CoQBdAAAADmf3YA0659efzMbCSPOK6SZttkfus7aWBDhrZZyX63Szl256BRcpz81LH6rIuONldYv256tsN7Zv-N6ZkOkJadlD2VS01bs7C4ierKvGUMyJOJu657xL5MvidF3Tgs9iejeJcXsxjDJYOwtN3m3sbfClfWYVnnIL4hMLYV8P9TnEhBurfJv_30CAG2wp1V73POVGhR-7fz1mCdh4OYWSa3Pw0mPupckoQ",
"scope":"GOOGLE",
"types":["hospital","pharmacy","store","health","establishment"],
"vicinity":"1012 Union Street, Bangor",
"html_attributions":[]}
My guess is there are a couple ways to get around this. You might remove the keyword argument from the API, which acts like a search term rather than a specific match on a type of location like the type field does.
You may want to be careful about your radius value choice.
Next, if you do a search on Google Maps in general you'll get a broad assortment of results. Do you need every result to be an actual hospital or can you do your own filtering afterwards?
If you do your own filtering it looks like type information and even icons are embedded in the result JSON. You might see if there's a distinguishing characteristic between the types of results you want and filter by that. Otherwise, any additional graphical data would not be accessible via the API.
Is it possible to have the Geocoding API works and sometimes doesn't work for some reason?
Here is the detail what I am trying to request:
http://geocoder.cit.api.here.com/6.2/geocode.xml?app_id=DemoAppId01082013GAL&app_code=AJKnXv84fjrb0KIHawS0Tg&gen=4&country=Australia&state=Tas&district=Wynyard&postalcode=7321&street=86 Jackson Street
and Here is the demo version from the official website:
http://geocoder.cit.api.here.com/6.2/geocode.xml
?app_id=DemoAppId01082013GAL
&app_code=AJKnXv84fjrb0KIHawS0Tg
&gen=7
&housenumber=425
&street=W+Randolph
&city=Chicago
I am using the Free version of it and I have no idea why it works sometimes and doesn't in other times.
Thank you
When you are making a structured address query, by default, all parts of the address need to match. Given that there is no international standard for addresses, the HERE geocoder could be placing parts of the address in an alternative part of the structure.
In your case Wynard is recognized as a city, not a district. Now it is possible you could want this to fail as an invalid address, but it is also possible to tell the Geocoder to be a little more lenient by using the FlexibleAdminValues parameter in the AdditionalData
see the User Guide here
FlexibleAdminValues
N (positive integer <= 1). Customizes flexibility in the input values
for the admin hierarchy defined in LocationFilterType. The value is a
bitmask defining which hierarchies might be swapped without impacting
the match level:
0: No swapping at all (default). Exact admin hierarchy values are
expected as input
1: City and District swapping
Please note this
option is for geocoding addresses and needs at least street level
input to work as designed. It will not return expected results when
the input is a named place only (e.g. city or district name).
So the following url will work for you provided you have a street address:
http://geocoder.cit.api.here.com/6.2/geocode.xml?app_id=APP_ID&app_code=APP_CODE&gen=7&AdditionalData=FlexibleAdminValues,1&country=Australia&state=tas&district=Wynyard&...etc
Another alternative is to not use the structured input parameters but let the HERE Geocoder sort out the identification and categorization of the input tokens.
By using the searchtext parameter and providing all your data as the input value the Geocoder can match and score the tokens.
E.g.: http://geocoder.cit.api.here.com/6.2/geocode.xml?app_id=DemoAppId01082013GAL&app_code=AJKnXv84fjrb0KIHawS0Tg&gen=7&searchtext=Australia%20Tas%20Wynyard%207321%2086%20Jackson%20Street