Find the nearest store to a customer-VBForums
Results 1 to 5 of 5

Thread: Find the nearest store to a customer

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    From the UK
    Posts
    422

    Question 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

  2. #2
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,572

    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, VB6, Photoshop...

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    From the UK
    Posts
    422

    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?

  4. #4
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,504

    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.

  5. #5
    Moderator
    Join Date
    Jan 2005
    Location
    Sydney
    Posts
    13,621

    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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.