Google places api only include results that have postal_code - google-maps

Is there a way of having a search input where a user can type a city name and it only returns results that have a postal code?
For this particular situation we don't want the user to enter the full address.
The fields we need are City, Postal code and Country.
I know we can limit the results by setting the flag types=(cities) but when searching for city name the first results never include the postal_code.
I though of doing a reverse lookup with the provided city coordinates but some cities have more than one postal codes.

It's not currently possible to filter places from Place Autocomplete predictions on postal codes only.
However, there is an open feature request in Google's Issue Tracker which I suggest starring to increase visibility and subscribe to future notifications:
https://issuetracker.google.com/issues/35822067
Hope this helps!

Related

How do I find city type in Google Autocomplete API?

I'm retrieving Google autocomplete data in JSON format, and I'm keen to know in which Object Array does Google sends "City" data because when I analyze the address types sometimes the city is found in post_town other times it is found in locality, sub-locality, administrative_area_level_1, administrative_area_level_2, administrative_area_level_3, administrative_area_level_4, administrative_area_level_5 .
The reason to find the city in correct type is that I need to write a code where I'll be using Google-type to identify the city and then storing into my database.
Can someone please help me identify to solve this issue?
Note: If you see the image below the city is identified in type: postal_town:
enter image description here
enter image description here
Unfortunately, there is no complete documentation about address components structure based on each country.
The only place I know in the documentation that mentions address components for cities is the following page
https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform
It reads
the sample code selects the locality component, which often represents the city part of the address. Examples of how components can differ include:
In the UK and in Sweden, the component to display the city is postal_town.
In Japan, components differ across prefectures.
Brooklyn and other parts of New York City do not include the city as part of the address. Instead, they use sublocality_level_1.
For other countries you should figure it out yourself based on the Google Maps API responses.
I hope my answer clarifies your doubt.

Find city in Google Geocoding API

I am using google Geocoding API to store the cities in the DB on demand.I provided an input field for the user to enter their city.I used googles places autocomplete for that.
I would like to store the city and its country what ever enter ed in the input field. Calling google geocoding API with the with data from input field, returned data in JSON.
I looked into address_components got country in it. Then I took object in address_components where types = locality. The problem is,For some locations typed in the input field, The JSON from google geocoding API doesn't have types = locality. So in these cases, which one among the objects in address_components should I store as city in my DB.
this website is exampale of google geocoding api https://findcity.in/
Need suggestions. The question may not be clear earlier. So I edited it. Thanks
You are right, the type locality is not always present in the address components array. Depending on the country or even regions of the same country the city name might be found in different address components. This depends on the data modelling for certain area and address templates that uses Google. Unfortunately, there is no documentation for this on per country basis.
In the official documentation you can find the following explanation
The selection of specific address components in this example is based on a typical address format. You may need to select different components to align with the postal address formats of different countries. For example, the code selects the locality component, which often represents the city part of the address. However, note the following examples of how the components may differ:
In the UK and Sweden the correct component to display the city is postal_town.
In Japan, the component differs across prefectures.
Brooklyn and other parts of New York City do not include the city as part of the address. They use sublocality_level_1 instead.
source: https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform
I hope this helps a bit.
administrative_area_3 indicates a third-order civil entity below the country level.
An example of this would be a search query for Montgomery returning Montgomery County in your specific state before Montgomery, AL. This is partially due to region biasing returning specified results based on your current location.
Here is some documentation from Google Which goes over the GeocoderResult.
I'd like to encourage you to make sure to take a look at the Google Maps APIs reference guide before asking a question directly. It is rather robust and you can find a lot of useful information there.

Google maps api request using components issues with postal code

I am having an issue with finding an address when all I have is the street number + street name and a postal code (assuming in US).
Using url parameters like:
address=1234+street+rd%2C12345%2Cunited+states
seems to always interpret <12345> as part of the street, like a sub unit or something. Using components parameters like:
address=1234+street+rd%2Cunited+states&components=postal_code:12345
will find the correct postal code but does not return the address information for the specific location like street number and name.
If I also add the route component and specify the street name then the full address information will be returned. Likewise if I use the locality component, then the full information will be returned:
address=1234+street+rd&components=locality:city+land|postal_code:12345
address=1234+street+rd&components=route:street+rd|postal_code:12345
The issue is I am using the geocoder to parse the addresses so I am relying on a full address response to get the components. In this specific case Im assuming the user only entered a postal code and street info so I dont have the option to include locality (without using a second maps calls) nor do I want to assume Ive broken down the street info correctly.
Can anybody shed some light on possible issues Im running into or possibly how to make a maps api call with only street number, street name, postal code, and country being known?
The Geocoding API documentation says the following:
A query containing a component filter only returns the geocoding results that match the filter. If no matches are found, the geocoder returns a result that matches the filter itself.
https://developers.google.com/maps/documentation/geocoding/intro#ComponentFiltering
So, if address=1234+street+rd%2Cunited+states&components=postal_code:12345 founds a postal code it is likely because the address is missing from Google database.
You have an option to report missing addresses as described here:
https://support.google.com/maps/answer/3094045?hl=en&ref_topic=3093612
Hope this helps!

Google Geocode API Address Formatting United States

This question is similar in spirit to. http: //stackoverflow.com/questions/7764244/correct-address-format-to-get-the-most-accurate-results-from-google-geocoding-ap
I've read the FAQ on the google geocode developers guidelines and it states that the suggested format for addresses is based off the country's postal service. In some of my testing this is not always working and sometimes I'm seeing better results putting the street at the end of query.
example being: http://maps.google.com/maps/api/geocode/xml?address=+3700%20W%20FLAMINGO%20RD++LAS%20VEGAS+NV
This returns zero results, but swapping road to the end returns a correct result:
http://maps.google.com/maps/api/geocode/xml?address=++LAS%20VEGAS+NV+3700%20W%20FLAMINGO%20RD
On top of that if I include the zipcode (89103) to the second request, that one will return no results as well.
Can anyone help me to understand what the appropriate format should look like for US addresses?
Thanks much!
-Chris
The answer you can find in this document
https://developers.google.com/maps/faq#geocoder_queryformat
How should I format my geocoder queries to maximise the number of successful requests?
Specify addresses in accordance with the format used by the national postal service of the country concerned.
Do not specify additional address elements such as business names, unit numbers, floor numbers, or suite numbers that are not included in the address as defined by the postal service of the country concerned.
Use the street number of a premise in preference to the building name where possible.
Use street number addressing in preference to specifying cross streets where possible.
Do not provide 'hints' such as nearby landmarks

Google Map API V3 Weighted Search Results

I was wondering if anyone knows if it possible to weight search results based on country or other variables?
Basically, what I'm looking to do is have user enter a street address but search Canada before searching the rest of the world.
The issue that I am encountering is users are not inputting their full address (inc. Province and Country) and the map is defaulting to addresses outside of Canada.
Is this even possible?
Is this even possible?
Yes! See Component Filtering.