views:

1070

answers:

7

I would like to build an app that heavily relies on Google Maps. Is it possible to write a native iPhone application in HTML/Javascript ? If so, will it be accessible from the app store ? Otherwise, how could I include Google Maps in a native app ?

A: 

The way to do this is to build your app as a regular web app (javascript/css/html). The embed that in a native WebView. The WebView is a container for iphone apps that are meant to be web apps. These apps are sold the same way as other apps on the app store.

darren
+3  A: 

You will need to build a framework application in Objective-C that contains a UIWebView. You can populate the UIWebView with your HTML/Javascript.

In my opinion the better alternative is to use the MapKit framework from a native app. MapKit lets you do almost everything you can do using the full Google Maps API and I think a native app will always work better on the device than a UIWebView container app.

I have used MapKit in a few of my apps and found it easy to use with nice performance. In the linked example I embed a MkMapView in a UIScrollView in page mode. I doubt you would have an easy time implementing this with a UIWebView and I am sure it wouldn't perform as well.

Cannonade
+1. My goal with HTML/Javascript was to "write once, run everywhere". However, I might look into MapKit to optimize things if my app gets traction on the iPhone :) Btw, is it possible to communicate between the native app and Javascript ?
Olivier Lalonde
Not that I can think of. Your javascript is running in the isolation of the UIWebView. I have never tried this, so I might be missing something here.
Cannonade
It is possible to communicate between Objective-C and JavaScript. Calling a JavaScript function from Objective-C is straightforward; calling Objective-C code from JavaScript requires a workaround. See http://www.codingventures.com/2008/12/using-uiwebview-to-render-svg-files/ for more information.
Steve Harrison
@steve-harrison Thanks Steve. I'm interested to see how this works :).
Cannonade
A: 

It's not possible to write a native iPhone app in HTML/JS, http://code.google.com/p/iphone-google-maps-component/ may be of some use, or you can use:

UIApplication *app = [UIApplication sharedApplication];
[app openURL:[[NSURL alloc] initWithString: @"http://maps.google.com/maps?g=London"]];

Please see http://stackoverflow.com/questions/30058/how-can-i-launch-the-google-maps-iphone-application-from-within-my-own-native-app for more info.

ridecar2
+1  A: 

In iPhone OS 3.0 and greater apple has created a custom Cocoa Touch control that allows developers to embed Google Maps into a native app. The maps support multi-touch and you can annotate the maps with custom views, find the user's current location and do other cool stuff.

zPesk
+1  A: 

Yes, it is possible to do this. There is a great opensource project called PhoneGap http://phonegap.com/ that allows you to do exactly that. Not only but alos deploy on other mobile OSs like Android, blackberry etc.

To get on the app store, you need to register as an apple developer which is about US$100. Development can only be done on a mac) Apple gives you lots of software tools including code editors and iphone simulator.

buzzspree
+1. I'll take a look at PhoneGap.
Olivier Lalonde
+1  A: 

Addressing the two parts of your question:

Is it possible to write a native iPhone application in HTML/Javascript ? If so, will it be accessible from the app store ?

There's a framework called NimbleKit that allows you to write your app in HTML/JavaScript and then converts it to Objective-C/Cocoa for you. There are several problems with NimbleKit, though:

  • It costs $99.
  • It adds a level of indirection that increases the chance of errors.
  • Because you're not using the 'real thing', you're much more limited in what you can do (i.e. you can only use what they have made available to you).

Another solution is to embed a UIWebView in a native iPhone app (you'll have to use a bit of Objective-C/Cocoa to do this) and then write the rest of your app as an iPhone web app that is loaded into the UIWebView. However, I would strongly advise you not to write an iPhone web app, whether standalone or embedded in a native app. As of writing, iPhone web apps have many disadvantages, including:

  • They're very slow.
  • They have limited functionality (e.g. no device APIs).
  • They can't take advantage of the Cocoa-Touch framework (a serious downside).

iPhone web apps may become viable in the future, but at this point in time, I'd steer away from them and write a native iPhone app using native technologies (i.e. Objective-C/Cocoa).

Otherwise, how could I include Google Maps in a native app ?

Use Apple's framework "MapKit". See Displaying Maps and Annotations in the iPhone Application Programming Guide, this tutorial, and this tutorial for information on how to use MapKit.

Steve Harrison
A: 

There is also Appcelerator Titanium, which looks to be a good framework for developing iPhone and Android applications using web technologies. They gave an interesting presentation on this at C4.

However, trying to "write once, run everywhere" on mobile devices will cause you to create something that is inferior on all platforms to native applications, because you will need to design for the lowest common denominator between them.

Brad Larson