We are using Google Places API for getting some locations in a map. The thing is, we have some issues with autocomplete (I believe related with browser language) because if you want to look for places in Panama City, you can write "Panama" and it will return "Panama City" as a prediction result. But, if your browser is in Spanish (our users speak Spanish), the user could write "Panama" and we would like to have "Ciudad de Panama" as a result, but we don't. The option in this case is to look for "Ciudad de Pa" for getting the result, but this is something that we don't want to have.
May be, the option is getting the predictions by "contains" method, instead of "starts with". Is it possible? Any other idea?
Thanks,
I think Google Place Autocomplete API results are already based on what you said "contains" method. I tried to get what you want and use "Ciudad de Panama" as my input and get many results not only start with input "Ciudad de Panama" but also get results like "Panamá, Doctores, Ciudad de México, México".
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Ciudad%20de%20Panama&types=address&language=es&key=your_api_key
So I think Autocomplete API does not return all results that contains what you search. Also, I think it gives priority in the search string what word you input. For example, as you observe on the results in the above request, I search the word "Ciudad de Panamá", the first result will give the exact word, the second and the rest will not. So if you use "Panama" as input. It will prioritize to results an address that contains "Panama" itself than a word that contains Panama as second or third word in the results.(xxxxx xxxx Panama)
Related
I'm using the Google Maps Geocoding API web service, and I'm using the components parameter to restrict results to 'London'. My URL query is here:
https://maps.googleapis.com/maps/api/geocode/json?address=<address>&components=administrative_area:london, united kingdom
This works super well and I only get results which are within London. However, if I ask for something definitely not in London, (e.g 'Manchester'), I simply get a default return relating to 'Greater London'. I would rather it simply returns the ZERO_RESULTS status. Is there a way to specify this?
P.S I have tried to use the region parameter, but this isn't as tight as I want it to be.
Using information found on https://developers.google.com/maps/documentation/geocoding/intro#ComponentFiltering
You can filter by a city (locality) and country as two separate filter components and these can be separated by the pipe (|) symbol. The country is the ISO 3166-1 country code [https://en.wikipedia.org/wiki/ISO_3166-1] therefore GB in order to cover the city of London.
Therefore, this format could be used :
https://maps.googleapis.com/maps/api/geocode/json?address=<address>&components=locality:London|country:UK
With that in mind, and addressing your exact question, according to
https://developers.google.com/maps/documentation/geocoding/intro#ComponentFiltering
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.
So it seems it will always try to find partial match when there are no exact matches and this cannot be disabled unfortunately.
However, if you do a check for "partial_match" : true in the result set, you could filter out such results in your code that deals with the response.
In Summary
This format seems to give results without "partial_match" : true if the address is ‘good’
https://maps.googleapis.com/maps/api/geocode/json?address=<address>&components=locality:London|country:UK
And it will allow you to filter the response for "partial_match" : true in your code to exclude spurious results. For example, using an address 'Manchester' :
https://maps.googleapis.com/maps/api/geocode/json?address=Manchester&components=locality:London|country:UK
Putting it simply, we have some Norwegian postcodes and are using the API to get their addresses and lat & long. Nothing to highbrow, but on around 10% of the postcodes. The API returns no results, here's an example:
Success for postal_code=1151:
http://maps.googleapis.com/maps/api/geocode/json?components=country:NO%7Cpostal_code:1151&sensor=false
Fail for postal_code=2066:
http://maps.googleapis.com/maps/api/geocode/json?components=country:NO%7Cpostal_code:2066&sensor=false
I have noticed that the majority appear to be for the Postboks (presuming equivalent of PO boxes in the UK).
However, it's not true for all of them.
Has anyone similar experience and or perhaps a better knowledge of Norwegian postcodes?
Thanks
I tried your given request, and I found that postal_code=2066 give you ZERO_RESULTS, If you are looking to the name Jessheim, am I right? Then I think you should use the postal_code=2069, this will give you the request that you want.
Here is the request that I used.
maps.googleapis.com/maps/api/geocode/json?components=country:NO|postal_code:2069&sensor=false
Also, I think you should know first the correct/available postal code that you used. I tried to request generally in which I did not set any country as a filter.
First, I used the postal_code=1151, and as you can see, you will find the 1151 Oslo, Norway address in the result. Which means the postal_code 1151 is available in Norway.
maps.googleapis.com/maps/api/geocode/json?components=country:|postal_code:1151
Second, I used the postal_code=2066, and you will not find any address that the country is NORWAY.
maps.googleapis.com/maps/api/geocode/json?components=country:|postal_code:2066
For additional note, if you use two components value in your request.
You need to use pipe(|) to separate them. I hope I help you with this
:)
KENDi - thanks a lot for your help and answer. I found out that Norway has two types of postcode. One is for the street addresses, the other is for postboxes (or PO Boxes in the UK) that don't have an geographical address.
Here's an example
http://adressesok.posten.no/en/postal_codes/search?utf8=%E2%9C%93&q=Molde
I'm a bit stuck in all the options the Wikipedia api has.
My goals is to get the amount of words of an wikipedia page.
I have the url of the wiki.
The search option does return this value:
http://en.wikipedia.org/w/api.php?format=xml&action=query&list=search&srsearch=camera&srlimit=1
Wil return
<api>
<query-continue>
<search sroffset="1"/>
</query-continue>
<query>
<searchinfo totalhits="68658"/>
<search>
<p ns="0" title="Camera" snippet="A <span class='searchmatch'>camera</span> is an optical instrument that records image s that can be stored directly, transmitted to another location, or both. <b>...</b> " size="43246" wordcount="6348" timestamp="2014-04-29T15:48:07Z"/>
</search>
</query>
</api>
(scroll a bit to the right and you find wordcount
But this query is making a search and shows 1 top result. However, when I search on the wikipedia name in the URL, it doesnt always find that record as the first result.
So is there a way to get this wordcount a Wikipedia page?
No other APIs provide this information, so the kludge with list=search is the only way. If you know the exact title you can get better results by appending &srwhat=nearmatch to the query (it will always return 1 result though). See the docs and try the sandbox to learn more.
Note that word counts are not stored in database so the API has to go to Lucene/Elasticsearch for this information which is not exactly fast, so if you need this information en masse you should download a dump instead.
I have use the code given below, please copy and paste in your URL, which gives latitude and longitude of a specific place.
But when I have used the same call with wrong place it returns latitude and longitude. How to check whether it is right and wrong?
http://maps.google.com/maps/api/geocode/json?address=dubai+United+Arab+Emirates&sensor=false
http://maps.google.com/maps/api/geocode/json?address=anu+India&sensor=false
Thanks
A typical scenario for using geocoding will be when you know that the address exists and you want to get the location coordinates, maybe to mark on a map. When you search an address in google geocoding api, it will find exact matches and also partial matches to correct for cases like spelling mistakes or multiple spellings in use. Due to partial match, when you search for a word, words close to that in terms of the letters used and the number of letters present will also be found. You can explore 2 options to refine the results:
1, If you want to avoid partial matches , you can try component filtering , where you specify filters on components like locality, country , etc and only exact matches will be returned.
2, You can process the json result in your code by retreiving different components and doing comparisons and taking only cases matching your requirement.
notice that on google maps you can input the address any way you like. as long as it is a valid address...google maps will read it.
In some ruby book I had seen code snippet for something like this, but with phone numbers.
Any ideas how this could be done for addresses?
in language of your choice.
EDIT:
i dont care about a "valid" address. I just want to parse an address. so that 123 fake street, WA, 34223 would be an address and so will 123 fake street WA 34223
it is not trivial task. first you have to have base of all streets, populated places and may me countries (if you want international look up). then try to find each word from input string in each list and try to find matches for all words.
You could create a regular expression that would match each format you want to accept. When one of them matches, you will know how to parse that particular string. If you think about it, there probably aren't more than 10 common formats people will use to type out an address 99.9% of the time.