iphone and gis development notes
By Rupert
By Rupert
Nov 2nd
Problem: I want my textFieldSearchAddress to display a seperate viewcontroller.

Short Answer: Hide the keyboard by using
[textField resignFirstResponder]
then show the view controller.
1. Implement a UITextFieldDelegate.
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{ [textField resignFirstResponder]; [self show]; return NO; }
Be careful with the BOOL return of textFieldShouldBeginEditing. From the docs: “YES if an editing session should be initiated; otherwise, NO to disallow editing.”
2. Show the view controller.
- (IBAction)show{ NSLog(@"show"); AddressViewController *addressViewController = [[AddressViewController alloc] initWithNibName:@"AddressViewController" bundle:nil]; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:addressViewController]; [self presentModalViewController:nav animated:YES]; [addressViewController release]; [nav release]; }
Nov 1st
This post will contain a summary of information regarding subversion scattered from old posts.
1. Packages
#apt-get install subversion #apt-get install libapache2-svn
2. Login as root then create the repository.
#cd /data #svnadmin create /repos --fs-type fsfs
3. Set the permissions
#groupadd subversion #addgroup rupert subversion #addgroup www-data subversion #chown -Rf www-data:subversion /data/repos #chmod -Rf 770 repos
It’s better to set the necessary users and groups that would use subversion now. Later on, if we need to checkout using svn+ssh and setup a passwordless svn, then we won’t get permission issues.
4. In /etc/apache2/sites-available/2rmobile, add this to the configuration.
<Location /repos>
DAV svn
SVNPath /data/repos
SVNAutoversioning on
AuthType Basic
AuthName "SVN - Your Project"
AuthUserFile /data/svn-auth-file
Require valid-user
</Location>5. Enable the webdav module then restart apache.
#a2enmod dav #a2enmod dav_svn #/etc/init.d/apache2 restart
On your local macbook pro (mbp), we need to generate the ssh keys from the local machine, upload it to the remote machine and append it in the authorized_keys.
On the local machine:
#ssh-keygen -t rsa ... #cd /Users/rupert/.ssh #scp -r id_rsa.pub rupert@2rmobile.com:/home/rupert/.ssh/id_rsa_mbp.pub
On the remote machine:
#cd ~/.ssh #touch authorized_keys #cat id_rsa_mbp.pub >> authorized_keys
Test on the local machine by doing
ssh rupert@2rmobile.com
. In my mbp, a dialog box from keychain is asking for the password. To circumvent this, we can add the passphrase to our identities.
#ssh-add -K ... enter the passphrase twice... #ssh-add -k (adds it to the identities) #ssh-add -l (lists the identities)
Now the benefits of having a passwordless svn:
- ofcourse it saves us a lot of time
- rails capistrano deployment
References:
http://www.howtoforge.com/debian_subversion_websvn
http://subversion.tigris.org/faq.html#ssh-authorized-keys-trick
1. Checking out using svn+ssh and having passwordless ssh authentication. My personal favorite when working with personal projects since I have full control.
svn co svn+ssh://www.2rmobile.com/data/repos/web/rails/halalan2010 halalan2010
But for work projects, I normally use webdav
svn co "http://www.2rmobile.com/repos/web/halalan2010" halalan2010
2. svn+ssh on a custom or different port other than 22. I have my ssh on 2210, so we need to tell svn+ssh to use 2210
vim ~/.subversion/config 41 [tunnels] 42 ### Configure svn protocol tunnel schemes here. By default, only .... 53 ### built-in ssh scheme were not predefined, it could be defined 54 ### as: 55 ssh = $SVN_SSH ssh -p 2210
http://www.techper.net/2009/01/11/changing-port-number-of-svnssh-subversion-protocol/
3. svn diff – shows you the changes in a directory. This is useful for creating patches.
svn diff -r HEAD svn st -q
3. svn switch oldURL to newURL - very useful when I’m working at home or in the office, since the svn server has a public/private IP.
4. svn log – shows you who committed and why (from the messages)
5. ignoring specific files in a directory. i.e rails directories
svn propset svn:ignore "*.log" log
Oct 29th
In this tutorial we will be addking MKMapView using IB to a ViewController.
1. XCode -> File -> New Project -> View-based Application.
Name the project “SimpleMapIB”
2. Make sure everything works out accordingly before doing anything. Let’s test from the iPhone Simulator. Click on “Build and Go”. You should see the iPhone Simulator running with a gray background. Bring up the Debugger Console (XCode -> Run -> Console) as well and it should be free from errors.
3. Now double-click on “SimpleMapIBViewController.xib”, it should open in Interface Builder.
4. Drag a UIToolbar to the bottom. We will use the button as a GPS in our next tutorial.
5. Drag MKMapView to the middle of the screen.
6. IB -> save
7. Now we need to reference Mapkit. Go to XCode -> Project -> Edit Active Target “SimpleMapIB”. Click the + icon on the bottom left, choose MapKit.framework, then “Add”.

You should see Mapkit added to the frameworks.

You could also organize XCode’s left panel by dragging “MapKit.framework” to the Frameworks Group.

7. Let’s code SimpleMapIBViewController.h
#import <UIKit/UIKit.h> #import <MapKit/MapKit.h> @interface SimpleMapIBViewController : UIViewController { IBOutlet MKMapView *mapview; } @property(nonatomic, retain) IBOutlet MKMapView *mapview; @end
8. Now back to IB. Click on the “File’s Owner” and you should see your outlets displayed “Connections Inspector”. Drag “mapview” to MKMapView Control.

Note: You can click for a bigger image.
9. Now to set “SimpleMapIBViewController” as the delegate. Click on the MKMapView, it should be highlighted and in the “Connections Inspector” notice the “delegate” come out in the Outlets. Drag it to the “Files Owner” to set “SimpleMapIBViewController” as the delegate.

Note: You can click for a bigger image.
10. Now, let’s test. Hit “Clean All” then “Build and Go”. You should see something like this..

11. Now to test that the delegate is setup accordingly, we can code on the viewDidLoad.
- (void)viewDidLoad { mapview.mapType = MKMapTypeSatellite; [super viewDidLoad]; }
12, Now press command-Y for “Build and Debug”. We should see a satellite map instead.

13. That seems a little bit dull, lets add a segmented control so we can switch between maptypes (standard, satellite, hybrid). In IB, drag a UISegmentedControl in the UIToolbar at the bottom. Add another segment, making a total of three. Then change the titles to “Normal”, “Sat”, “Hybrid” respectively.
.
14. Let’s code. In the interface, we need to add a method that would be called by the segmentedControl whened the values changed.
#import <UIKit/UIKit.h> #import <MapKit/MapKit.h> @interface SimpleMapIBViewController : UIViewController { IBOutlet MKMapView *mapview; IBOutlet UISegmentedControl *segmentedControlMapType; } @property(nonatomic, retain) IBOutlet MKMapView *mapview; @property(nonatomic, retain) IBOutlet UISegmentedControl *segmentedControlMapType; - (IBAction)changeMapType: (id)sender; @end
Now in IB, click on the “File’s Owner” and you should see your outlets displayed “Connections Inspector”. Drag “segmentedControlMapType” to the segmented control just like what we did for mapview.
15. In the implementation, we can switch between the segmentIndex and display the corresponding MKMapType.
- (IBAction)changeMapType: (id)sender{ if(segmentedControlMapType.selectedSegmentIndex == 0){ mapview.mapType = MKMapTypeStandard; } else if(segmentedControlMapType.selectedSegmentIndex == 1){ mapview.mapType = MKMapTypeSatellite; } else if(segmentedControlMapType.selectedSegmentIndex == 2){ mapview.mapType = MKMapTypeHybrid; } }
16. Now to hook the IBAction of the UISegmentedControl to the method. In IB, click on the segmented control and in the “Connections Inspector”, drag the “Value Changed” Event to the “File’s Owner” and choose “changeMapType”.
17. Now test in the simulator again and the hybrid button should work.

In my next tutorial, I would be hooking up a GPS button which handles location updates using CoreLocation.
Oct 20th

I can not argue enough how valuable an iphone stencil will be in seeing the overall design/flow of an application. I should have done this a long time ago.
Well, I am also one of those eager developers who dives right into coding and see how it goes. But after having the fundamentals of iphone development, objective-c, and app-store submission, I’m taking on a different approach by creating screen mockups mainly for the following reasons:
1. Reach out quickly to the client.
2. Provides a bird’s eye view of the whole application. Provides alternative screens for a better user experience..
3. A follow up on the screen mockups is a powerpoint with actual links to other slides thus mimicing an iphone interface. Note, it is not a complete replica of the simulator but just enough for decision makers to understand what’s in there.

In powerpoint, you can just quickly overlay a transparent polygon on top of the UIButton then attach a hyperlink to another slide.
Hope this post helps you even if it’s not related to coding. On my next post, which is currently buried in my drafts–hopefully it will not be that long, I learned about integrating with Mobile Advertising Networks.
Oct 5th
I am a programmer currently in Melbourne, Australia hoping to raise awareness for the victims affected by typhoon Ondoy (Ketsana-international name). Experiencing a flood is not new to me as I was born and raised in Tumana, Marikina, Metro Manila. I was in primary school, when I could vividly remember my mother cooking and serving porridge to typhoon victims as our backyard was called “high ground” since it is near the main road (JP Rizal).
I was in college when Tumana bridge was built and helped me travel from my house to the University. Unfortunately, the river would swell and the flood would swallow the whole bridge after 2-3 days of rain. I called my mother on Sept 27 and was informed the typhoon poured over a whole month of rain in just a few hours! Don’t worry my mother is fine, however, there are those who are unfortunate enough who desperately call for our help. In my small way by making this application, I would like to show my support for them.
I’m almost finished with the Bayanihan iPhone project which I worked on over the weekend. It is a very simple app with scrollable images. The server side is almost finished and would display how many supported/downloaded the application in real time. I am hoping to upload the server side to my Linode hosting in the US asap.
How can you help? I need pictures! Pictures from Tumana would be greatly appreciated, however, if you have other pictures, please do send them as well. I will be bundling 10 pictures inside the application. Please include your name, with subject: BAYANIHAN pix and send the pictures to my email address: rndguzmanjr@gmail.com
Hopefully I can submit the app to Apple within this week or early next week. Afterwards, we wait for the approval process within 2 weeks. Note, the app would be FREE.
UPDATE OCT-05-2009 9:00PM
I took some pictures from facebook and dropped it in the project. It would look something like this when it is finished.
UPDATE OCT-11-2009
- Included proper credits for each photograph.
- Added Admob.
- Created logo, large application icon.
![]()
UPDATE OCT-12-2009
Preparing for appstore submission..
UPDATE OCT-13-2009
Submitted in AppStore. Currently, In-Review.


Comments