I'm developing a little web application with PHP, I have some address in my database (state, town, city) - "the state is always the same". But town and city vary.
Is there any way to force a preference search by location? For example, preference is always looking in the state of Delaware in USA.
So I can pass parameter something like this:
var address="{$city}, {$town}, Delaware";
The problem is that by doing this, I sometimes get results from other countries, is there any rule or algorithm to do what I want?
Thanks for reading :-)
You could try appending " Delaware state" or " Delaware, USA". There isn't any documented rule I know of, except that it attempts to match "postal addresses".
Per the documentation you can bias the search:
by viewport
by region code
Related
I'm using Google Map's Geocode API to get the lat, lng values for this address in Manhattan:
123 Dr Martin Luther King Jr Blvd, New York, NY 10035, USA
My initial query looks like this: https://maps.google.com/maps/api/geocode/json?address=123%20mlk%20blvd
This query does not return my desired address, so in order to filter down results to only those in Manhattan I modified by request to include the Component Filtering parameter locality:Manhattan.
As defined in the docs here: https://developers.google.com/maps/documentation/geocoding/intro#ComponentFiltering
So my question is - why does this url: https://maps.google.com/maps/api/geocode/json?address=123%20mlk%20blvd&components=locality:Manhattan not return my desired address?
And yet - using the component filter postal_code:10035 does return my desired address: https://maps.google.com/maps/api/geocode/json?address=123%20mlk%20blvd&components=postal_code:10035
Thanks
I think the main detail you should be aware of is that Google changed behaviour of components filters recently. This change was made on January 15, 2018. The documentation contains the following text now:
Filters on route, locality, and administrative_area influence the results but do not guarantee containment in the same way as an address query.
source: https://developers.google.com/maps/documentation/geocoding/intro#ComponentFiltering
That means that currently only postal code and country continue to be enforced strictly for components filters. The Component Filtering in the Geocoding API is no longer as strict as it was before. This change explains behaviour of your sample requests. Component filter with locality is not strict, so you get different result, while component filter with postal code is strict and you get expected result.
If you need a locality you should include it in the address parameter of your request to make it less ambiguous.
E.g.
https://maps.googleapis.com/maps/api/geocode/json?address=123%20mlk%20blvd%20Manhattan&key=YOUR_API_KEY
You should follow the best practices of Geocoding API that are available at:
https://developers.google.com/maps/faq#geocoder_queryformat
https://developers.google.com/maps/documentation/geocoding/best-practices
I hope my answer explains your doubts!
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 want to filter the Google Places API results for a specific City. The filter has to be made by exclusion, not by sorting. I know I can specify the location and radius but that's not enough, because that only priorities the search results.
The level of filtering I desire is the same available for Country.
My urlCall looks like this:
https://maps.googleapis.com/maps/api/place/autocomplete/json?components=country:pt&types=address&input=INPUT&language=en-US&key=MY_KEY
What I'm doing right know is iterating through the JSON result and evaluating if there's a term with the city name.
Thanks in advance!
Other solution (more performance friendly) is to check if the city name is present in the description field. But still, not as good as the country filtering system.
Why don't you match the administrativeArea if your goal is to filter our the city?
The (cities) type collection instructs the Places service to return results that match locality or administrative_area_level_3.
places API resource
When a user of my web site enters an address, he often does it like this:
street_number street what_he_thinks_is_the_locality
When I store it or display it, I need to show it better like this:
street_number street, true_locality
I use the geocoder service to extract the address components so that I can format it correctly. I rely on the type of the component to find the locality and I expect "locality", "sublocality" or "administrative_area_level_3". But today I saw a user enter an address and the locality was returned as the {"neighborhood", "political"} type.
What is neighborhood exactly? When is it returned? Was it returned because the google API detected that the user was at a certain "near location" from the result? When this type is returned, should I include the next address component to remove all ambiguities?
Thanks
A "neighborhood" is generally a small community within a city (often times a housing development). It is different from a "sublocality" in that it usually is not an administrative boundary.
Example 1: SoHo (neighborhood), Manhattan (sublocality/borough), New York (locality/city), NY (administrative_area_level_1/state)
Example 2: Cap-Saint-Jacques (neighborhood), Pierrefonds-Roxboro (sublocality/borough), Montreal (locality/city), QC (administrative_area_level_1/province)
Google's geocoder is not perfect. It may contain errors, such as Bay Ridge in the Brooklyn borough of NYC for which Google returns Manhattan as the sublocality. Similarly, in example 2 above Pierrefonds is listed as the sublocality, rather than Pierrefonds-Roxboro.
The geocoder is also incomplete at times. Zip code 02130 is in Boston, yet the geocoder does not return a "locality". It only returns the Jamaica Plain neighborhood. However, if you add Jaimaica Plain to the Zip code, then it does return the locality (a possible workaround, though it requires two requests).
What you likely experienced is this later case. It's not clear what conditions trigger it. You'll need to account for the fact that the results are not always complete.
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.