Need help doing a search via postal/zip code, and address using Objective-C, and SQLite

Posted on 2010-09-07
Last Modified: 2012-06-22
Dear fellow iPhone developers:

I am trying to develop an iPhone app that will show the user, the closest specialty restaurants to where they are using Objective-C I want my app to mirror the following app:

which shows the user the closest "Tim Horton's" coffee shop to him/her.  One option it offers, is that it allows the user to do a search by postal/zip code to find the closest locations to that particular postal/zip code.  How is this implemented?  I will be having a sqlite database table that will have the following columns:

-street address
-postal/zip code
-phone number

How can one implement a search via postal/zip code using a sqlite database, and also, how can one implement a search by address?  I am using a navigation based application, and would also like to know how to trigger this search by clicking on a button.  Where would the button code be placed?

Thanks again for your time, and patience.
Question by:fsyed
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 24

Assisted Solution

fridom earned 500 total points
ID: 33634179
Please check first

And if you understand what is done there, please send some compilable code which shows your problems. You just have to build a proper query and well that's all there is to do...

Author Comment

ID: 33658296
Thanks for reply.  My problem is not so much with setting up the database in SQLite.  Here are the specifics of the issue:

1.  A table to have my locations, as well as their corresponding lat/lon co-ordinates.
2.  Another table to hold all postal/zip codes, and their corresponding lat/lon co-ordinates.
So when a user submits a postal/zip code, the first thing the app should do is check against table 2 and retrieve the corresponding lat/lon co-ordinates, and then calculate the distances between it, and the ones in the first table.  Am I correct so far?
If I am correct, then I have two follow up questions:
1.  Wouldn't table 2 be quite large?  Especially if it is to hold ALL postal/zip codes, and their respective co-ordinates since the user can be anywhere.  Is this something that would hinder performance?  Just wondering.
2.  After finding the relevant lat/lon co-ordinates for the user's postal/zip code, is there a way that I can retrieve only those postal/zip codes that are "relevant" or near the users given location instead of calculating the distance between the user, and ALL locations in the first table?  I am asking this because it seems that this could be an issue on performance, considering that the first table may have thousands of locations, and to calculate all the distances between the pairs of co-ordinates, and THEN retrieve only those close to the user, seems like overkill.  Is there a better, more efficient way of doing this?

Thanks again for your help.
LVL 24

Accepted Solution

fridom earned 500 total points
ID: 33659740
Well Databases are there to handle large amounts of data. The table 2 would not be large by any Database means. Just see the phone book of your city. I guess you'd qualify it as beeing large but it's really a small one.

to 2. well you can look up an area around your searched for location. Of course you must have a way have a way how "far" away other coordinates are. So you search in the database for a longitude in a specific range around your current longitude, and than you do the same for the latitude. I don't know if this could be of any help but check if you can't make something out of the map from google. There this is solved for massivly many points of interest. and you can see the "distances also".

Author Closing Comment

ID: 33685529
Thanks for that last post, I had never thought of that as a possibility, but I can see how that approach would definitely work!

Thanks for your time, and patience!

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
CodeTwo Sync for iCloud ( automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question