-
Oct 21st, 2011, 04:38 PM
#1
Thread Starter
Hyperactive Member
Find the nearest store to a customer
I have a form where the client is able to enter a post/zip code. I would then like this to be matched against a database of stores and to output the nearest 3.
How would I set something like this up? I'm wondering if I could save the store information in an XML file? However the difficult bit is working out the closest matches to the customers post/zip code. Can anyone help point me in the right direction on how to do this?
Thanks
-
Oct 22nd, 2011, 01:10 AM
#2
Re: Find the nearest store to a customer
Suppose your user's postal code is 12345, then you could query your database to check whether an exact match is found or else list those which are in between 12340 and 12350.
I'm not much sure about the postal codes, I mean how they are numbered. So, what I said was based on assumption.
The query might look something like this:
Code:
SELECT store_address FROM tblStores WHERE store_zip = '12345' OR (store_zip >= '12340' AND store_zip <= '12350')
I haven't tested it.
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Oct 22nd, 2011, 02:42 AM
#3
Thread Starter
Hyperactive Member
Re: Find the nearest store to a customer
I understand the logic but I'm not sure if that will work as I'm not sure if postal codes are numbered in that sort of way.
I was wondering if there is any function/API/script which works this out - anyone know?
-
Oct 23rd, 2011, 12:10 PM
#4
Re: Find the nearest store to a customer
I believe Google Maps has an API to get the langitude/longitude coordinates of an address (or part thereof - like a zip code); you can store the coordinates of your store locations, then do an API call on user-submitted addresses and compare for the nearest locations. I'd try to find some resource links for you, but I'm on a mobile device at the moment.
-
Oct 23rd, 2011, 08:26 PM
#5
Re: Find the nearest store to a customer
Maps API: http://code.google.com/apis/maps/index.html
If you only need to search your own store locations, I would save the coordinates of each store in your database and execute a query ordered by distance ((customer latitude - store latitude) + (customer longitude - store longitude)).
See if you can use the Maps API to get the customer's coordinates.
The bonus of using the Google tools is that they will accept any sensible sort of input: suburb names and street addresses as well as postcodes.
Last edited by penagate; Oct 23rd, 2011 at 08:31 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|