Posts tagged with apple

How to launch Google Maps or Apple Maps from an iOS app

Today Google announced their much-anticipated Google Maps app for iOS. They also plan to make available a Google Maps SDK for iOS allowing iOS developers to integrate Google Maps in their apps, however at present API keys are only available for selected developers.

If you want to provide your app's users with the ability to open a location in Google Maps, there is an option which works today: Google have added a comgooglemaps URL scheme to their app so third-party apps can launch the Google Maps app.

Assuming you'd like to give your users a choice of opening a location in both Apple or Google maps, you can set up some code like this in a new view controller:

  1. #import "ViewController.h"
  2. #import <MapKit/MapKit.h>
  4. @implementation ViewController
  6. - (void)viewDidLoad
  7. {
  8. [super viewDidLoad];
  9. // Add a button to pop open an action sheet
  10. UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  11. btn.frame = CGRectMake(80,100,160,50);
  12. [btn setTitle:@"Open placemark" forState:UIControlStateNormal];
  13. [btn addTarget:self action:@selector(openActionSheet:) forControlEvents:UIControlEventTouchUpInside];
  14. [self.view addSubview:btn];
  16. }
  17. -(void)openActionSheet:(id)sender {
  18. //give the user a choice of Apple or Google Maps
  19. UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Open in Maps" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:@"Apple Maps",@"Google Maps", nil];
  20. [sheet showInView:self.view];
  21. }
  22. -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
  23. //coordinates for the place we want to display
  24. CLLocationCoordinate2D rdOfficeLocation = CLLocationCoordinate2DMake(31.20691,121.477847);
  25. if (buttonIndex==0) {
  26. //Apple Maps, using the MKMapItem class
  27. MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:rdOfficeLocation addressDictionary:nil];
  28. MKMapItem *item = [[MKMapItem alloc] initWithPlacemark:placemark];
  29. = @"ReignDesign Office";
  30. [item openInMapsWithLaunchOptions:nil];
  31. } else if (buttonIndex==1) {
  32. //Google Maps
  33. //construct a URL using the comgooglemaps schema
  34. NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"comgooglemaps://?center=%f,%f",rdOfficeLocation.latitude,rdOfficeLocation.longitude]];
  35. if (![[UIApplication sharedApplication] canOpenURL:url]) {
  36. NSLog(@"Google Maps app is not installed");
  37. //left as an exercise for the reader: open the Google Maps mobile website instead!
  38. } else {
  39. [[UIApplication sharedApplication] openURL:url];
  40. }
  41. }
  42. }
  43. @end

Here's the app in action, example code is on Github.


For more details, see the Google Maps URL Scheme documentation.

Barcamp: this is a placeholder

A few weeks ago I promised Kevin from TechYizu that I'd do a talk at Shanghai Barcamp. "What will the talk be about?" he asked me. "Just put a placeholder in the list of talks for me", I replied.

I got distracted doing other things and the placeholder talk sat there in my calendar, reminding me about the event on September 8th. So in the end, I decided I'd prepare a talk... on placeholders!

I'm going to try to persuade you that placeholders - those little pieces of text that hint to you what the real content will look like - are worth your attention. There are four reasons why...

Continue reading...

Apple iOS5 Tech Tour in Beijing: Performance tips

Last time we discussed some of the tips Apple gave at the recent iOS5 Tech Tour stop in Beijing on how to get your app noticed in the App Store.

Naturally, there were also plenty of informative technical sessions that touched on just about any part of the API you might be interested in, but one that really stood out was the "Performance Hitlist" talk.

Here are some of the key points Apple mentioned that you may want to consider when creating your app:

Continue reading...

Apple iOS5 Tech Tour in Beijing: Getting your app noticed

Fluxa and I attended Apple's iOS5 Tech Tour in Beijing this week. It was a great event and there were a ton of fantastic sessions with Apple Engineers on hand to answer any questions. We learned a lot of interesting information on the technical side, but also got some great tips about what Apple is looking for when they decide which apps to feature.

Continue reading...

Is it time to drop support for iOS3?

It's no secret there are a lot of really cool features and APIs you can take advantage of in iOS4 and iOS5 that are not available in iOS3. And while it's definitely possible to maintain backwards compatibility by littering your code with version checks, it can quickly turn into a quality control nightmare.

On the other hand, dropping support means ignoring potential users or upsetting your existing ones. How many though?

Continue reading...