Google Geocode API - Postal Code not returned - json

I have a site that validates zip codes. If a user types in a zip code I store the formatted address, lat, long, etc. If they go back in to edit the form the next day, I set the field to the formatted address and revalidate. The problem is not all formatted addresses return the zip the second time - even though I'm passing it in to the query.
-- RETURNS FORMATTED ADDRESS: Woodland, CA 95776, USA
https://maps.googleapis.com/maps/api/geocode/json?address=95776&key=
-- DOESN'T RETURN A POSTAL CODE - GIVES APPROXIMATE EVEN THOUGH I'M PASSING IT IN
https://maps.googleapis.com/maps/api/geocode/json?address=Woodland, CA 95776, USA&key=
-- RETURNS POSTAL CODE AS EXPECTED, EVEN THOUGH LENEXA, HAS MULTIPLE POSTAL CODES
/maps/api/geocode/json?address=Lenexa, KS 66227, USA&key=

I would suggest storing the place ID instead of the address string. This is recommended by Google:
https://developers.google.com/places/web-service/place-id#save-id
So the first time you execute
https://maps.googleapis.com/maps/api/geocode/json?address=95776&key=YOUR_API_KEY
and store the resulting place ID ChIJARdFFWLRhIARK6RIUxEbJ30.
The next time you should execute the place ID lookup to get exactly the same result as the original request
https://maps.googleapis.com/maps/api/geocode/json?place_id=ChIJARdFFWLRhIARK6RIUxEbJ30&key=YOUR_API_KEY

Related

Sort numbers by string

Hi I am using an API from Postcode Anywhere, the idea being to add a company by searching by postcode to select the address, this is pretty standard and the code works fine.
Just some background info, PAW works in two stages, 1 the post code search criteria is sent off to their services, which returns an array of possible addresses, you then select the address you want, and in stage 2, the full PAF file for that ID is returned and stored to the table.
The problem I am having is that the array they send includes an Address Field which includes house number and street address in one field, making it difficult to sort alphanumerically.
This is the sample data I have in my table:
and this is how it looks in my application:
As you can see it is not ideal and I have no control on how they send the data.
Does anyone have any ideas on how I can search a string based on numbers that can be 1, 11, 2, instead of 01, 02, 03, etc, or at the very least be able to split this into two rows. Also please note, that it most cases, the post code search will result business/property names as well as house numbers, as seen in this example.
Any thoughts would be greatly appreciated.
Have you considered using a different API provider for the data, Allies Computing (who I work for) have a single step API, where the initial postcode search returns all fields in the response. It also orders these results by premise number/name.
Give it a try here - https://developers.alliescomputing.com/postcoder-web-api/address-lookup/premise
There are also other providers of PAF data that do it this way such as Crafty Clicks and Ideal Postcodes.
It might also be worth checking the PAF license with your provider to ensure you comply with that too.

query yahoo apis WEATHER return me NULL- by JSON

I try this query
http://query.yahooapis.com/v1/public/yql?q=select%20item%20from%20weather.forecast%20where%20location%3D%2248907%22&format=json
with Weather API yahoo but it returns me NULL...
{"query":{"count":0,"created":"2016-12-14T12:48:16Z","lang":"fr-FR","results":null}}
I want to receive data in JSON to work with
Thanks
The Yahoo API has changed over the last years, right now for the location you need the WOEID, that you can obtain in various ways:
select woeid from geo.places(1) where text='paris,FR'
Writing the previous query in the sample API search in this Yahoo site, where text must be equal to the city and country you desire.
The previous step can be done with a call to the API from your own program, just encode the query.
Clicking 'Change location' in this page and finding your desired city, once the new page loads, the WOEID will be in the browser's URL.
Once you have the code, the call to the api must be done with the following query encoded.
select * from weather.forecast where woeid = 615702 and u='c'
Where woeid is, the number you obtained and u is optional, f value returns Farenheit and c, celsius. But it's worth noting that the first returns imperial units and the second, metric.
Also, in the first link there are examples about limiting what the JSON returns, but you may want to look at the documentation they provide.

Querying Geonames API to get only city country name

Too much useless json data is being fetched when I request a specific country cities by hitting this URL:
http://api.geonames.org/searchJSON?username=ksuhiyp&country=us&maxRows=1000
This returns too many json fields as you can see, question is hot to play with the query to get only city, country name ?
You can try with the additional parameter style=SHORT
http://api.geonames.org/searchJSON?username=ksuhiyp&country=us&maxRows=1000&style=SHORT
The docs says: style, String SHORT,MEDIUM,LONG,FULL (optional), verbosity of returned xml document, default = MEDIUM

Address parts, proper order

if I look up this address:
Maanweg 174, 2500 BD The Hague, Nederlands
google maps finds it perfectly. if I look it up this way:
Maanweg 174, The Hague, Nederlands 2500 BD
It does not, because the postal code is out of place.
Now my question: I have 4 fields: Address, City/Region, Country and Postal Code. if the user starts to type the address, a lookup on google maps comes up with a list of addresses the user can pick from. I break the user selection appart and fill-in my 4 fields.
However... if the user changes some part of the address, I need to reconstitute it into a string to feed it to google... but I don't know the proper order. in the Netherlands, the postal code goes after the address. in the US it goes at the end, right before the country.
how can I find out what the proper order is?
There is no unique format, you should use the format as it will be used in the particular country (see: https://developers.google.com/maps/faq#geocoder_queryformat )
According to http://www.bitboost.com/ref/international-address-formats/netherlands/ the order of the first example is correct(for the Netherlands).

Get only country specific result using google geocode api

I am using google geocode api for fetching lat long using postal code of singapore
I have tried following to fetch data:
(1) http://maps.googleapis.com/maps/api/geocode/json?address=505468&sensor=false
(2) http://maps.googleapis.com/maps/api/geocode/json?address=Singapore%20505468&sensor=false
(3) http://maps.googleapis.com/maps/api/geocode/json?address=Singapore%20505468&sensor=false&region=sg
But it returns location from India
https://developers.google.com/maps/documentation/geocoding/?hl=fr#RegionCodes
Any other way to get only country specific (Singapore) result.
I have tried following it returns correct result
http://maps.googleapis.com/maps/api/geocode/json?address=Singapore%20133224&sensor=false
The correct way of doing this is by providing componentRestrictions
For example:
var request = {
address: address,
componentRestrictions: {
country: 'UK'
}
}
geocoder.geocode(request, function(results, status){
//...
});
To restrict results to a specific country use the component-filtering.
The url should be http://maps.googleapis.com/maps/api/geocode/json?address=Singapore%20505468&sensor=false&components=country:SG
But that's not the issue here, the geocoder-result is wrong, because the result has the country set to SG, but the location is wrong(placed in india).
I'm afraid with the given address(it appears that the postcode doesn't exists), the only thing you can do is to report the wrong result to google.
you can set single country or multiple countries
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Raf&sensor=false&types=(regions)&key=YOUR_API_KEY&components=country:ESP
or
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Raf&sensor=false&types=(regions)&key=YOUR_API_KEY&components=country:ESP|country:uk|country:us
You should be able to use this approach
http://maps.googleapis.com/maps/api/geocode/json?components=country:US|postal_code:5037
remove the address and to the component pass the postal code and make sure if the address has a value let pass another value selected by the user with the postal code to validate your api or else without postal code passed it will leak to another address