Save Map Annotation - ios

I just created a map view where the user can make an annotation by dropping a pin. How is it possible to save the annotation, so the user can see it when the app is closed and re-opened? Does anyone know a good tutorial for saving map annotations? Thanks!

Map annotations are nothing different to regular data. The answer to this will depend on many things. For example:
How do you save other data in your map?
How many pins do you need to keep track of?
If you are only saving one pin and thus one lat and one long value, you could use NSUserDefaults. There are lots of tutorials for that around. Here's just one example: http://iphonedevsdk.com/forum/iphone-sdk-tutorials/106311-tutorial-1-how-to-use-nsuserdefault.html

Related

Long-tap/drag/drop Skobbler skannotation to new position

I'm looking to allow my users to drag & drop annotations on my maps, initiated by a long-press on the annotation pin. I can't find anything in the documentation that would handle this.
Can someone point me in the right direction?
Edit: I realize I may not have been as clear as I thought I was.
Currently, my users are able to add new annotations to the map by long-pressing at a location on the map. I'd like for them to be able to move those annotations to a different location.
For adding a new PIN, the SKMapViewDelegate protocol is used to receive map-related update messages.
Check: http://developer.skobbler.com/docs/ios/2.4.0/Protocols/SKMapViewDelegate.html

iOS how to save map annotation and load them on a mapkit?

Do any of you know a way in Xcode where I can save the coordinates of an annotation every time a person puts an annotation pin on the map.
Then after I save this annotation, when a person clicks a button. The map shows all of the annotations ever saved and shows their location on the map.
I think this is the most difficult problem in IOS because I don't see any tutorials or sample code. I don't think we know how to do this. Any geniuses??
Thanks
The way to do is,store annotation coordinates somewhere in the app.
You can store annotation coordinates in local xml/plist file or any another saving flat file saving mechanism and load them on fly. The other option is to use iOS CoreData (sqlite data store). Once you have them saved some where its all mater of reloading and using them..
I personally prefer coredata since it gives bit more flexibility than flat files..

MKMapView. create a path on the move

I am trying to create a line on the MKMapView after the users path.
I've found this rather old post, and i'm trying to make it work as explained in the accepted answer:
Does anyone have any examples on how to create a path using MKOverlayPathView?
What is don't get is how to "extract" the array of CLLocation objects mentioned. Right now i have set the mapView setShowsUserLocations:YES, and it updates my movement perfectly fine, so i guess i can get the CLLocations objects somehow, and continuously draw the line?
Im still very now to iOS, so be gentle.
Check out the source code of Apple's BreadCrumb sample app for an example of how to draw the user's path with an MKOverlayView. It does exactly what you are asking and it is quite efficient. It's an excellent example app for getting started with core location and mapkit in iOS.
The idea is to have an object conforming to the MKOverlay protocol that has a property for an array of coordinates that the user has logged. When the user logs a new position you will add a coordinate to this array. Your MKMapViewDelegate is then responsible for providing an MKOverlayView for your overlay. Your MKOverlayView class is then responsible for drawing lines in between the points in the array of the user's logged coordinates. This occurs in the MKOverlayView's drawMapRect:zoomScale:inContext method. Note, you will have to pay special consideration to the fact that drawMapRect:zoomScale:inContext will be called by multiple threads. If you don't acquire a lock on MKOverlay's array of coordinates when adding a new coordinate you will almost definitely experience crashes. See the Breadcrumb code for an efficient way to keep you drawMapRect method thread safe. A less efficient but much simpler alternative is to not access the MKOverlay's array directly from your MKOverlayView but instead pass a copy of it.
The map will show the location pin but it won't actually notify you as your location changes. You want to add your controller as a delegate of CLLocationManager and use startUpdatingLocation. You will then get updates to location that you can save and use to add overlays to the map.

customizing info window for multiple markers

I have seen the google developers video on custom info window for google maps ios sdk and got it. But how to use it when we have multiple markers. In my application i have to point 10 place and have to use that custom infowindow
I got it, we just have to call the customInfoWindow class how many time we want with new set of parameters.
Not sure exactly if this is what the question was - but you can attach a piece of your own data to the marker using marker.userData. You can make this anything you want - an NSDictionary for example. In -markerInfoWindow:(GMSMarker *marker) you can retrieve the userData and based on that, you can decide what view you want to return. Make sure the userData contains sufficient data to decide what your view should contain and you are good to go.

iOS mapview issue/question

I have an App I am developing for iOS, and the app does the following
Load and set annotations and launch corelocation and zoom to location.
There are a lot of annotations on the map, the loading from data doesn't take long, but the actual rendering of them them to the map takes a while.. so the user interface sort of stalls for a little bit, and then finally gets the corelocation and zooms to it.
While this is functional, it is less than ideal user experience.. I could invert the order, than do the corelocation zoom first and then call the add annotations, but this would cause a pause to the UI as well since annotations are added in the UI thread, and not to mention that corelocation could take a little time to get its location first too.
So, the question I guess I am asking is what is the best way to handle this? Is there some way I am unaware of to have the annotations render to the map without tying up the UI? I could show some sort of Splash Screen I guess over the map while this is going on, but that seems a cop out, and I personally hate splash screens.
Maybe the best way to do this is to show the BUSY/WORKING spinner over the map until its completed?
What is generally considered best practice?
You could use OCMapView to cluster all annotations. As already mentioned, the map can handle a bunch of annotations but the performance goes down with the number of drawn views and MKannotationViews don't make a difference.
OCmapView clusters all annotations and displays them merged in a single annotationView. try it out, it's free.
https://github.com/yinkou/OCMapView
I wound up simply doing the same thing I did with the android version, while iphone can handle the larger number of annotations far better than droid, the lazy loading approach certainly is a better overall experience for both platforms.
Thanks for the help guys.
I think your best solution would be to simply not add "a lot" of annotations to the map. MKMapView has a lot going on and it doesn't take a ton of annotations to bog it down. There are a number of creative ways that you can go about reducing the number of annotations.
If you have a lot of annotations that are grouped tightly together, consider aggregating them into a single annotation which then split apart into separate annotations when the user reaches a satisfactorily close zoom level.
Another consideration would be to default the user to a tighter zoom level and only add annotations that are currently on screen at that zoom level and position.
Do either of those options sound viable or get you thinking about another creative way to help your situation?

Resources