1

I have been tasked with creating an iPhone application for a client.

I have some coding experience but only in C# so it doesn't really help here but other than that I am a complete novice on iPhone coding.

What I am trying to accomplish is to get some form of store locator on a map.

I have successfully added the map, get the user location with it zooming into the user. I have added 2 annotations (Which I believe the the best way to go about showing locations on the map).

I have 2 queries that I need help with, What is the best way to go about listing the stores in some form of database. XML, PList, .sql etc... (this would also need to be read from the web as it would need to be easily edited as new stores would be added a lot). Is it possible to loop through the database and dynamically add the stores onto the map within a location of the user?

I am not asking anyone to write any code for me, I am just asking for some help as I have googled the hell out of this and cant seem to find anything that helps.

Any help would be much appreciated,

Thanks

  • 1
    Search for SQLite and MKMapView for some starting hints. Here's a previous answer: http://stackoverflow.com/questions/7104178/mapkit-coordinates-from-sqlite-database – nevan king Apr 29 '13 at 15:55

3 Answers3

1

In terms of your potential formats for saving these locations, you options include:

  • XML/JSON are good formats for exchanging data with a remote server, but less ideal for a local database (though they theoretically could be used for that purpose). JSON is marginally easier to deal with (using NSJSONSerialization), but XML can be relatively easily parsed, too (using, for example, NSXMLParser). If you're doing network operations, I also heartily recommend looking at AFNetworking, which offers some nice advantages over the standard NSURLConnection. This, of course, presumes that you have written a web service on your server to deliver the necessary JSON or XML feed.

  • Plist is a fine, simple format if you want to save a short, local list of locations on iOS devices. Saving data to a plist is as simple as calling writeToFile method for your NSDictionary or NSArray and reading data is done via [NSDictionary dictionaryWithContentsOfFile:filename] or [NSArray arrayWithContentsOfFile:filename].

  • Core Data is a good, iOS-specific format for larger databases. It's probably the preferred iOS mechanism for dealing with persistent objects, but is an order of magnitude more complicated than plists.

  • SQLite is also a good database format if you're thinking about a structure that lends itself towards larger database, but also which lends itself towards eventual rollout to multiple platforms (e.g. both Android and iOS). If you decide to go SQLite route, consider an Objective-C wrapper (such as FMDB), which will simplify your life greatly.

Implicit in all of the above discussion is that, yes, you certainly can write code that iterates through your database and/or model data structures, extracting the necessary location information, and dynamically add annotations to your map. The Location Awareness Programming Guide should help introduce you to some of the MapKit related features.

Rob
  • 415,655
  • 72
  • 787
  • 1,044
  • Hi rob thanks for your reply. I have been thinking about using SQLite database as i've used SQL before. Is it possible to read the database from a remote location? Or does the database have to be local to the device? – Lewis Halliday Apr 30 '13 at 06:35
  • @LewisHalliday - Alas, SQLite interface is for local database. Typically you have a remote web service with which your iOS app interacts and then have a local database for operation of the app. You can might be able to find third party libraries that wrap all of this together for you, but (a) they don't have widespread adoption; and (b) I'd be very wary of this sort of architecture due to network latencies (you want apps that are responsive, retrieving data from a local database and perform web service requests asynchronously). – Rob Apr 30 '13 at 13:40
0

"Is it possible to loop through the database and dynamically add the stores onto the map within a location of the user?"

Yes. Just as you have created those first two annotations, you now need to create more annotations in a loop. The only additional info you might need is that once you have added an annotation to the map it will stay there until you remove it. So you don't need to maintain your own list of annotations unless you want to do something else with it. Just fire and forget. So now your question comes down to how to loop through data from your chosen data source in Objective-C and not MapKit specific.

Craig
  • 8,093
  • 8
  • 42
  • 74
0

I know this is old but if anyone else comes across this like I did, you can use tmysqlkit by tanmay bakshi to read and write directly to a mysql database on a server.

Best, Sam

Sam S
  • 1