Managing thousands of annotation's in iOS - iphone

So im making an iOS application where I have a map that contains thousands of annotations. And my question is the following:
The annotations are loaded from a site database and i query for new ones whenever the map is moved but this results in querying for the same annotation several times, does anyone know a good algorithm for not doing this?
And a follow up question: I only want to show annotations if im at a certain zoomLevel(I have implemented zoomlevels in my map just like in the googleMaps API). Can I somehow make some annotations invisible at a certain zoomlevel? In that case how do I do it?
EDIT:
Thanks for the tip Sanjay Chaudhry. Although I went with a slightly different approach for grouping annotations than what was suggested in the video. Although I still dont know how to effeciently query the server for annotations without flooding and querying for annotations already received.
EDIT2:
I still havn't found a good apporach on how to query for new annotations from the site without querying for ones already aquired.
Does anyone know some smart algorithm for splitting up countries into MapRects?

If you're a registered developer, watch the following video from WWDC 2011. It has a demo doing exactly that:
https://developer.apple.com/videos/wwdc/2011/includes/visualizing-information-geographically-with-mapkit.html#visualizing-information-geographically-with-mapkit
Essentially, if there are many annotations in a small geographic area, they're replaced by a single annotation as the map is zoomed out.

MapKit does a pretty good job of managing annotations -- it's often better to add as many as you can at once than to keep adding and removing them as the map moves. Annotations can be very small objects -- all you need is enough information to find the related data when you need it -- so you can add thousands at once without being too concerned about using too much memory.

Related

Graphstream MultiGraph to SingleGraph at runtime (and vice-versa)

I've only started using Graphstream a couple of weeks ago, and so far it is working pretty well, but I have one issue that I have not been able to solve:
I am displaying data which for smaller datasets is nice to view as a MultiGraph, and for larger datasets becomes to hectic and would be nicer to view as a SingleGraph. What I'm trying to accomplish is at runtime to either dump the data from a SingleGraph into a MultiGraph (and vice versa) on some user action. Either that or use MultiGraph all the time if there is some way to suggest to it to display only a single edge between nodes?
So far my only semi-reasonable-looking-to-implement-solution that I have thought up was maintaining both a SingleGraph and MultiGraph and swapping them out with the viewer when the user performs the swap action, but that seemed kludgy (and would have to do every operation on both graphs). I searched around the docs and web for quite awhile but have not come up with a reasonable solution so far...so if anyone knows of an easier way, please let me know :)
EDIT: Solution found (good enough for us anyway)
So what I ended up doing is adding another ui.class to the edges that are known to be duplicates at graph construction time, which for now I made a much less obvious color, so they fade into the background when you're trying to look at the singlegraph links. I could also use this to iterate over the graph and hide them (or just redefine the css to be the same as the background color...or something)...It's not quite what I wanted, but looks like it will serve us well enough for the near and medium term on this project.
Thanks,
-Dave

iPhone Database of People with Properties?

In the iPhone app I am developing, I need to have a list of people which is stored.
So the user go into the 'People' view and there I want a table view which the user can edit by adding and removing people to their list. Each person will also need to have properties, such as first name, last name, age etc as some examples.
I am unsure of how to approach this as its my first time. My main curiosities are how to have a list of people and go to a view displaying that persons unique properties. How to have each entry/person have its own unique properties (which I can define) and how to save/load them. It of course has to be persistent, so when the application is quit the data stays when reloaded.
Obviously code samples help understanding a lot, but any pointing in the right direction is really appreciated, thanks.
Too broad to really answer, but here's some pointers:
Use Core Data for storage.
Create a Person class, with each person being an NSManagedObject with various properties like first name, last name and so on.
Use an NSFetchedResultsController to populate a TableView with your people.
CoreData is the way to go. I have found this tutorial particularly helpful when I was learning iOS and CoreData.
http://www.raywenderlich.com/934/core-data-tutorial-getting-started
But Apple Documentation is good as well.
https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/CoreData/cdProgrammingGuide.html
Easiest: Use NSUserDefaults. Define a class "Person". Store instances of "Person" in an NSArray and save it in NSUserDefaults. It'll give you persistence but little else. If you have any search or data modification operations, you'll have to write your own code and it can become cumbersome pretty soon. For very simple apps only.
SQLite3: You'll need to know/learn about SQL a bit and also know how to design tables, but will keep your life simpler if you need to do sophisticated searches, etc.
Core Data: Apple's recommended solution to all your database needs. Highest learning curve, but simplifies many sophisticated tasks (undo operations, etc.). A good choice for 90% of the apps.

Alternate between different views using Objective-C

I am preparing an iPad app using, obviously, Objetive-C and wich tries to deploy Data Base stored content inside a view.
Now comes the problem, it will be a huge amount of records to be shown, each of them deployed inside some kind of "container" inside the view so that I was considering to make a page browser and in every page I go to change the view I apply.
Take for example, I show the first 5 items using example1.xib, for the next 5 example2.xip and so til getting to the page 10 and starting again with example1.xib.
My question is how this can be achieved? Maybe storing diferent view class based objects inside an array and alternating them or so...
Any help or hint would be greatly apreciated.
Cheers!
Always assume others have made similar apps before you. Perhaps not exactly the same ones as you, but doing similar things that you can learn from. The iPod and Spotify apps navigate large amounts of data using indexed, searchable TableViews. Go hunting on App Store for apps that have the same kind of functionality as yours, and test them out and grab what's good and discard what's bad about them.
My advice is to get hold of a nested tables example using the built in SQLite, and go from there. I've no idea what your database looks like, but with a bit of luck you could adapt example code and just open (a converted) SQL database.
Most users by now are used to the drill down paradigm rather than the paginated paradigm, so it's worth checking out the Drill Down example that comes with XCode even if it's not for databases (at least I don't think it is, I learned from a book, like Manuel.)
I would subclass UIViewController or UITableViewController depending on what type of records you plan on using.
I would recommend checking all the Apple's Examples, and most of the available online tutorial
Here are some, may be old though...
http://www.edumobile.org/iphone/iphone-programming-tutorials/tabbarcontroller-with-navigationcontroller-and-tableview-in-iphone/
http://www.aboveground.com/tutorials/adding-a-uitableview-to-a-custom-uiview
http://www.icodeblog.com/2008/08/08/iphone-programming-tutorial-populating-uitableview-with-an-nsarray/
http://blog.webscale.co.in/?p=150
http://www.ioschef.com/2011/03/un-aperitivo-de-uitableview-y-uitableviewcontroller/ in spanish..
http://adeem.me/blog/2009/05/19/iphone-programming-tutorial-part-1-uitableview-using-nsarray/ with videotutorial

UITableView theory help for a grizzled old web developer

I am a web developer who is trying to transition to Objective-C and Cocoa-touch. I am used to creating a table as a Dom element and then inserting it. If I wanted a link I did that as I went along. Obviously iPhone development is very different. I am looking for either a good explanation of hOw to wrap one's mind around the cocoa way of doing things.
Specifically I am looking to pull data from a web service and then make a drill down 3 or 4 levels deep. If there is a tutorial that shows how to do that perhaps I can learn through that.
Take a look at Apple's SeismicXML sample code. There's a lot in there, but it's basically what you asked for: an example of grabbing data from a web service and displaying it in a table.
There's a pretty big difference between creating a table on a web page and creating one in an iOS application. In the first case, you're actually writing down the data that gets rendered into a table by a browser. In the second case, you're creating a table object, and that table is like a living, breathing (compared to a web page, anyway) thing that can change through it's lifetime. The table will ask your code for data to display, and also what to do at certain points, such as when a user taps a cell.
Looking at a sample like SeismicXML is a good idea, but you'll still be mystified if you don't take the time to really understand what's going on. (I'm not saying you wouldn't, but there are plenty who don't and are confused to this day.) Go look, and then come back here if you have more questions.
The paradigm for iPhone tables is very different from HTML. On the web, you build the table and its elements and insert them into the DOM. On the iPhone, you have a proxy object that answers questions as the table builds itself. The table will ask the delegate how many entries it has and what it should put in each entry. That way, the delegate only needs to look up the information that is currently needed by the table, and not the whole thing, which may be only partially displayed. For instance, the delegate might to database queries as needed.
The simplest way is for your delegate to grab the info it needs from the web site and store it in an array for when the TableView asks for it.
The TableView itself is placed on the screen by calling addSubview: on a parent view.
You're asking more than one question here. You should split them up into multiple, more specific questions.
There are a variety of ways to make HTTP requests, anywhere from using the bundled classes like NSURL to using external libraries like ASIHTTPRequest. It also depends on what kind of data you are getting from the Web service -- there are various libraries to parse XML and JSON.
To make a "drill down" I assume you are describing table-based navigation. There are dozens of examples in the Apple sample code archive of projects showing off how to use UITableViewController, and probably hundreds available on Stack Overflow.

Tips for simplifying UI with large data model?

I'm working on an app for iPhone, and the data model looks a little crazy - 16 entity types. Could you offer any advice for masking complexity like this from the user? I know all these need to be there, but I'm trying to make it look simple, cause otherwise people will not understand.
The Tricks I have figured out so far:
My app is a bit secret in nature (in development) but use for example an app that deals with nature trips, i.e. hike, mountain bike, skiing, etc. Say I would have an object for a certain journey, i.e. by bike, through the rocky mountains (Journey: Mode of transport, location). Then I would have a different object type to store a specific journey, i.e. This january, do the rockies bike trip (Trip: Date, Journey).
Trick 1: I found that the user doesn't really grasp the difference between the two objects I just mentioned (trip and journey), and generally wouldn't care if I called them both "Trips" on the UI. (Try explaining the two distinct objects to a non-programmer, 25 minutes you'll never get back).
Trick 2: certain things, like for example pieces of camping equipment, may be objects to me, (equipment name, weight) but to the user they are just words, so I treat them as such and when they type it in my app says "You've never mentioned 'tent' before, how much does it weigh?" Then they tell me, and I have created an object without telling them it exists.
These kinds of tricks are what I'm looking for, my app needs to reduce these 16ish objects into maybe 3-4 the user is aware of, the rest hide in the mists, so anything I can get would help.
Thanks.
P.s. before you say it, I know, keep it simple, shouldn't have so many object types, etc. Just looking to find a workaround for this rule (guideline) with coffee and genius.
Stop trying to look at it from a data point of view. Rather, think about what the user is trying to accomplish with your app, from the most basic point of view.
Your nature analogy is too vague for me to help any more, maybe expound on that?