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

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..

Related

ios mapkit markers load their images in unpredictable way

So, i am using native mapkit and load markers in json format.When i parse my json i have a special parameter, which detects what image should be used as icon(from images.xcassets) for current marker.But every time i load it, smth goes wrong and image assigns in unpredictable way and when i scroll map to new position and then back, markers again change their icons .Moreover, the same algorithm works fine on android using native sdk.I don't think the problem is in parse algorithm, but in map itself.Any suggestions?
Have a look at reuse identifiers for annotation views. It sounds like you are reusing views when you don't want to be, thus the new image is never set.

adding annotations to offline map (tilemil)

I'm using tilemil to create offline map for my iPhone app. I've added annotation to map through GEOJSON, and everything works great, but i have one question: how can i create and hook up annotations that is created in offline map with app annotations. Because annotations that is created in offline map showing as dots in my app.
Example:
what i have:
what i want:
should i just parse GeoJSON and add annotations with data this way, or there's some better approaches to do this? Thanks!
If you have implemented the points in TileMill, then their imagery will be "baked into" the map raster tile imagery. You can still have callouts for these if you also add interactivity to the map in TileMill so that tapping the points can retrieve data. A good example of doing this for regions instead of points is in the third tab of this sample project, as shown in the screenshot:
https://github.com/mapbox/mapbox-ios-example
Another option, as you've mentioned, is to just parse the GeoJSON client-side using NSJSONSerialization and then adding the points in Cocoa as RMAnnotation objects.
A third option is to add the markers in the mapbox.com editor interface and save them with your map, then you can retrieve them as simplestyle data automatically as in the Weekend Picks sample project that you've included a screenshot of. The GeoJSON can be automatically retrieved, parsed, and added as annotations in the project by the iOS SDK.

Save Map Annotation

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

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.

iOS: smart refreshing of annotations

Whenever I move my map in my application I download new annotations(or coordinates rather) from a webserver, appropriate for the maps state.
I do not want to download already downloaded annotations again. I need a smart, selective way to download the new ones, avoiding duplicates.
You could grid off the map into sections and make requests based on tiles. that way you know if a tile has been downloaded or not and you can only request the tiles that are not yet populated.

Resources