I am building an web app (with PHP) that requires users to subscribe. I would like for them to identify where they are from. So what is the best way to validate there country/state(or province)/city/postal code? Is there a DB with all the information? Which one is the best?
There are many options for address validation. The main issue is how much traffic your website will receive and whether or not you need support. If you are relatively small, you can get away with the free services like the following:
Google Maps API (example) (you may be breaking the TOS)
UPS Address Verification API (example)
USPS Address Web Tools
If you need something more robust or customizable, it will probably be necessary to pay for a service.
I know this is old, but to prevent others from going down the wrong path, the chosen answer to use Google API's may not have been aware of the google terms of service license (...the Geocoding API may only be used in conjunction with a Google map; geocoding results without displaying them on a map is prohibited.)
If you're not using a map...
and your requirements do not require commercial grade data, this sums up some options and what to look for.
however, if you need commercial data, greatdata.com and melissadata.com both sell real commercial level data products.
This thread is also helpful: stackoverflow thread on zip code data
Use the Google Geocoding API They allow 2,500 requests per day and you can pay for more. It will take an address and give you very detailed information on it and provide validation if you code it into your application.
Use the USPS Address Information API.
I've utilized data that can be purchased inexpensively from http://zipcodedownload.com/ to provide zip code validation/address correction in our applications.
Related
Does anyone know of a piece of code that can run on a server that pipes the data from Apache logs into Google Analytics? I've got a bunch of websites that generate logs, but the users would likely object to injecting Google tracking codes into them. This might be a nice way to get the basics, what's being requested from where, and have it all sorted for me in with my other Google Analytics pages.
You can use the new measurement protocol (available for universal analytics account only) to implement a serverside solution.
Piping logs would probably not work very well (at least if you want to do a batch job - I don't think you can send a timestamp via the measurement protocol, so it would look as if all hits occured at the same time) but it shouldn't be necessary anyway, just create an url with the relevant parameters pointing to the google endpoint and sent it in the background via CURL (or similiar).
If you're in the European Union remember privacy guidelines still apply and you need to inform users and provide an opt-out link.
For non-Universal Analytics accounts, you can use php-ga - Server-Side Google Analytics Client -- it's essentially a server-side implementation of ga.js.
One caveat: If you want the location metrics to record something other than the location of your server, you'll need to log with a Google Analytics mobile tracking ID. Just replace the "UA" in the tracking ID with "MO", like "MO-12345678-1"
GA needs JavaScript, I think, so that various things like screen resolution can be grabbed. So even if this were possible, you'd be missing a good deal of info for some of your users, skewing your other percentages. Also, if your users are suspicious of Google, they probably would not want you to upload their IP addresses to GA.
With all that in mind, I wonder whether a self-hosted GA-like system would fit the bill? If so, try Piwik.
You see them on shopping carts etc, you type in your postcode and it gives you a list of house numbers, then the user selects the house number from the list... Is this just done with a database or is there anyway to do this using google maps or another api?
this is for the UK
I have implemented this before for clients. The only reliable way i found was to use a comercial API. the cheapest and most reliable i found to be "postcodeAnywhere"
http://www.postcodeanywhere.co.uk/
You will have to use an external web service to accomplish this.
As it is for UK only, that makes it easier, but there are no free API's which will do it.
You can however fill in the rest of an address (minus house number/name) using just the Post Code by accessing the google web service:
http://code.google.com/apis/maps/documentation/geocoding/#GeocodingRequests
This is free as long as you do not plan to have large numbers of requests per year.
This project is fairly simple yet, complicated.
50+ addresses are present
User will input or import addresses
Script must take addresses and provide non-optimized(or optimized [fastest/shortest]) direction between each address
Script must be able to map directions on map and provide information such as total distance, proximate time.
On side note script must validate address if it's valid or not. If not then tell user to fix it.
So far the company was using a desktop application for tracking, routing, directions, etc.
Now they want a web version.
I was thinking about using microsoft's bing service or google's maps.
Which do you think would suit better?
For address validation you could use Google's Geocoding API. It's not a perfect solution as it allows for addresses that might be partially wrong. An example is a user typing in 3002 Such and Such Street when 3002 doesn't actually exist.
Also, if the link doesn't have to be internal then you can provide a link to Google maps with the format http://maps.google.com/maps?saddr=[STARTING ADDRESS]&daddr=[DESTINATION ADDRESS]
I'd imagine there is also a way to handle directions with the Maps API but I'm not sure.
I am looking for a PHP script to parse through a name and address field, the kind that people attach to the end of their emails. It would be uploaded as plain text and would be in this format:
John Q. Public
Director of Some Thing
123 Elm Street
Anytown, ST 11001
(000) 555-1212
(000) 555-1213 FAX
The addresses tend to vary in format, which is why I am wondering if anyone has taken this on yet. Thanks.
Because addresses can vary so much, this is not a trivial parsing task. If possible, I would recommend using a proven service such as The Google Geocoding API.
You could use PHP's file_get_contents() to retrieve the answer and json_decode() to read it (JSON is one of several formats the Geocoding API can return).
SmartyStreets offers an extraction tool to do this sort of thing. You can paste in any block of text and it will scrape through to extract any addresses that might be in it. SmartyStreets specializes in address validation, so our developers have already sorted out the parsing problem. You can check it out here. The extractor is a web tool, but you can use it programmatically using PHP. It does require at least a free subscription.
Here's a look at what it found from your fake email signature above:
(Just to be clear, I do work at SmartyStreets.)
Google Geocoding has a limit of 2,500 per day.
If you have alot of data being parsed, I suggest using another services.
The cheapest geocoding api that can return a formatted address similar to Google would be Geocode Farm. They have jSON also, so you can still use file_get_contents with json_decode(). I would suggest you use their 25,000/day ($25/mo) and parse it out through that if you have alot of data. If more than that, upgrade to a different plan. If you only need 2,500 but more in the future, I suggest you still use them because they are free for 2,500 too and you can upgrade the plan instantly to paid one in their dashboard.
Kind of biased towards using GeocodeFarm because their service is the only one that I have found that is better than Google, dirt cheap, and returns close to the same results if not spot on most times. Never had downtime and love them. I use GeocodeFarm for all my geocoding and address parsing.
The down site:
They don't provide the address components as Google does, only the returned / corrected address... :/ Hopefully they add address components in the future. The only thing I've found that's missing. :(
P.S. Either Google them or I linked their site to the word "Geocode Farm" above...
P.S.S. Sorry for late reply, but hopefully this will help someone else who looks for this...
We have a client that wants a store locator on their website. I've been asked to find a webservice that will allow us to send a zipcode as a request and have it return locations within x radius. We found this, but it's maintained by a single person, and doesn't look like it gets updated or supported very well. We're looking for something commercial, ideally that updates their zipcode database at least once per quarter, and that has a well-documented API with PHP accessibility. I won't say price isn't an object, but right now we just want some ideas, and my google-fu has failed me.
I've already posted this over on the webmasters forum, but thought I'd cover my bases and post here too.
I've repurposed this outstanding script to conquor this same challenge. It's free, has been very reliable, and is relatively quick.
In my script, I have addresses stored in the DB. So rather than show a page to enter addresses, I simply pass them as a string and let the magic happen.
He says it in the app, but ensure that if you go this route you get your own Google Maps API. It won't work with his!
If you want to go a bit less technical approach, here's a MySQL query you could run on your locations (you'd have to add lat/long to your DB or setup a GEOCODING service) to give you distance as the crow flies.
Google Maps has a geocoder as well and it geocodes to the specific address.
It's limited to x number of requests but that shouldn't be a big deal if your site is small and if you cache. You can get more requests if you pay.
It can be accessed via javascript or via PHP (and there are several prewritten PHP modules out there)
Link here:
http://code.google.com/apis/maps/documentation/javascript/v2/services.html
(I worked for a company that did upwards of 800,000 requests a day, so it's stable and fast :) )
PostcodeAnywhere has a Store Locator feature - I think it's pay per use, but I've used their other products before and they're very cheap.
http://www.postcodeanywhere.co.uk/store-locator-tool/