Annotation pins and detail view from sqlite - ios

I've been looking around the Internet to find a tutorial or something to explain this.
I need to show some pins on a map. I need to get them from a sqlite database (table with POI's name, lat, lon, and some text). They have to show annotations callouts with title and subtitle and open their detail views.
All that with Objective-C.
How can I do that? Can anybody help and write the code?

I'd recommend using FMDB to get files from a local sqlite db. This stack answer is pretty helpful in getting started on that. It might take an hour to get up to speed on it, but you'll save that hour many times over once you're comfortable with it.
Now that you're able to retrieve data from your db, you need to create MKAnnotations for each pin you want to drop on the map. This tutorial is pretty short and to the point for what you're looking for. Also, don't worry about adding a lot of annotations, MapKit is optimized for have a large number of annotations on a map.
Lastly, you want to be able to go from an annotation to a detail view. MKAnnotationView has a property called leftCalloutAccessoryView where you can add a button. If you just want a quick and dirty fix, set the tag property on the button to the index in the array with the info for the detail view and have every button call the same selector.

Related

Advice about structuring data in Swift using TableView and mapping on GoogleMaps

I would like to get some advice. I am in the process of making an application where ideally a user can scan through a list of places, see some detail about the place (like name, perhaps some pictures) and be able to select the places they want and save it on a map.
For this I wanted to use Google API. I have created a tabbed application and in one tab I have the GoogleMaps and in another TableView which follows through onto a DetailTableView. My question is firstly, is it possible to link between tabs where upon selection of a cell by the user in Tableview would automatically map the place onto the GoogleMaps tab? Secondly, is there any advice about how to approach this? And how this type of database should be stored/structured? It would have to be a database which will allow access to be updated as well as the user to contribute perhaps.
In the initial table view I would probably just want the name of places whereas the Detailed table view should give more details such as Address, website link (if place is a business), opening times, related pictures etc...
I think you're better off checking Place Autocomplete as it deals with names of places and some details about them. It also has sample codes on displaying Table Views.
If you want additional code samples, check out Layering a table view and a google map view iOS Swift and Picker Places from Google Maps to UITableView.

Taking user input and displaying it in multiple view controllers in Swift?

This is my first post about Swift and I hope someone can help me. I'm a junior Ruby/Rails developer and have recently started building an app for a personal project to get to grips with developing in Swift and XCode, as it is something I am interested in moving into.
I have just started building my app, but have hit a problem almost straight away that I have been unable to find a clear answer to or any guidelines that I can bend to serve my purpose. I'm sure it must be a fairly simple issue to solve, so I'll try and write my problem as clearly as possible:
If I want to take some user input from a text field, such as a name or a location, and then display that input in another view controller, how would I go about doing it?
So far in my app, a user is presented with a button, which when pressed, shows a view controller with two text fields. I want to take the input strings from the two text fields and display that data in a label on the next view controller, so the user can add more information to the object before publishing it to be displayed in a table view cell elsewhere in the app. I have used IBOutlets on the text fields.
I have been reading about Core Data in Swift and have worked through a couple of tutorials about adding data to a table view, including the Start Developing iOS Apps (Swift) from Apple and I think I'm on the right track to finding out how to achieving the functionality I want. But I'm not entirely sure, and wanted to ask if I am on the right path or if I'm going about it the wrong way?
If anyone could link me to any tutorials or guides or point me in the right direction so that I can figure out what seems like a basic step of storing data that can be retrieved and displayed in other view controllers, I would appreciate it very much.
Thank you in advance.
You may do it by many ways -
If you want to take input string to the immediate next UIViewController, then when you navigate to another UIViewController , initialise two string object of that view from current UIViewController and then navigate. In that UIViewController you can have your string.
If you want to use those strings in some other UIViewController then you can take two string variable in AppDelegate(That is a global class) and set them from current UIViewController and you can use them whenever you want.
If you want to permanent save that data then you can better use NSUserDefaults ( NSUserDefaults - storing and retrieving data )if it is only 2 or 3 or some little amount of field data. If data is more you can use database.
Try these links :
http://jamesleist.com/ios-swift-passing-data-between-viewcontrollers/
How do you share data between view controllers and other objects in Swift?
http://blog.apoorvmote.com/how-to-pass-data-via-multiple-segue/

How to relate data to a specific row in a UITableView

What I basically want is to show the user's name in the first tableView but have a disclosure indicator (segue) to go to a second tableView which will show the history of the selected user. I know how to load data into a table and how to segue from one row to the detail table but I just don't know how to show different data for each user. I know this may be out of my scope of knowledge at the moment but I would like to give it a try.
1- What would be the best way to store the data for each user (history), an array per user?
2- How can I relate data to a specific user so it loads when the user's name is touched?
3- How can I capture the row being selected?
Any suggestions will be appreciated.
Honestly, you shouldn't worry about it being outside of your scope of knowledge, as that's how people learn. You will need to do some amount of work, however, and that part can be a little difficult.
Luckily, what you're trying to do is a very well documented function and Xcode even provides a template for master -> detail views.
Check out this wonderful tutorial by Ray Wenderlich on creating a simple master-detail application: http://www.raywenderlich.com/1797/ios-tutorial-how-to-create-a-simple-iphone-app-part-1
His other tutorials will also be immensely helpful to beginning iOS development: http://www.raywenderlich.com/tutorials

showing continents programmatically in MKMapView

I have a view with 3 buttons (Europe, Asia, America) and a MKMapView.
If one of these buttons was clicked, i need to show the specific continent.
In
MKGeometry.h (Mapkit Framework)
there is a constant
MKMapRectWorld
which i can use to show the whole world.
Is there something similar for continents?
If not, what is the best way to determine all informations i need for creating a MKCoordinateRegion?
Use Google Earth or Goole Maps to work out the lat/long boundaries and then call setRegion on your map view.

How to display two annotations with the same coordinates on the map?

I have two annotations with the same coordinates. And I have to display them on the map. When I add these annotations on the map I see just one pin. How can I display two annotations instead of one? Or how can I display a annotations list by clicking on the pin? Can anybody help me?
Thanks in advance.
Igor
When you try to display multiple annotations at the same coordinate on a map using MapKit, generally it will actually place two different pins, but they will be in the exact same location. You can compare the difference in the shadow strength to see the difference, however; look at a single pin's shadow, then look at your double-pin shadow, and you should see the latter appear darker.
In terms of indicating to your user that there are multiple pins, there are several ways you could do that. You might consider implementing the title or subtitle properties on your annotations to display the number of annotations at the same coordinates (e.g. set subtitle to the string #"(and two more)" or similar). Then, when the callout accessory view is tapped, push (onto a navigation controller stack) a table view of annotations at that location.

Resources