- Becoming an Apple Certified Developer
- Registering an iPhone and Other Apple Testing Devices
- Creating App IDs
- Creating a Developers Provisioning Profiles
- Creating and Publishing an iPhone App
- Controlling the Accelerometer
- Saving Images to the Camera Roll
- Understanding the Limits of Flash
- Identifying Devices to Deploy an Ad Hoc App
- Creating an Ad Hoc Distribution Profile
- Packaging an Ad Hoc App
- Packaging an App for the iTunes App Store
- Using iTunes Connect to Publish an App
- Using Screen Orientation in an App
- Using Geolocation in an App
- Using Multitouch in an App
Using Geolocation in an App
Mobile devices are meant to move. With GeoLocation services, you can figure out your current location. So, when someone asks you “Where are you?” you can tell them.
The following example shows how to add Adobe AIR 2.0 GeoLocation Class (New!) to your iPhone App. This sample is stripped down to a simple Class file, which can give you an idea of how you can use this in other Apps.
Add GeoLocation Services
- Create a new iPhone App, apply the appropriate certificates and profiles, and then save your file with the name iPhoneGeolocation.fla.
- Add a dynamic Classic Text box to the Stage with the name myTxt, and then apply the _Sans font.
- Create a new Class for the App with the name iPhoneGeolocation.
- Save the ActionScript file with the name iPhoneGeolocation.as.
- Add code to import the class files that allow you to use the Geolocation objects:
import flash.events.GeolocationEvent; import flash.sensors.Geolocation
- Create a new geolocation variable that you can use:
private var myGeo:Geolocation;
Create a simple If/Else statement that detects whether or not the geolocation services can be used.
The iPhone always gives the user of the iPhone a choice to whether or not you can use the Geolocation services. If you do not allow geolocation to be used a message will be posted to the text field informing the user that a location could not be detected. If you do, however, allow the user to use geolocation then a new listener event will be triggered and then re-run 10x/second.
- Add a function triggered by the geolocation listener: Publish and package your file into an iPhone App and test it on your iPhone.
- Publish and package your file into an iPhone App and test it on your iPhone.
How Does the iPhone Know Your Location?
There are three ways to detect your location. The most accurate method uses the Global Position Satellites (GPS) built into the iPhone 3G and 3GS. The second method uses Cell Tower Triangulation where the location of the device is determined by using 3 or more Cell Tower’s. This method can be used by all iPhones and 3G enabled iPad’s. The third method uses a WiFi hotspot, which is similar to the Cell Tower Triangulation but is only accurate to within a few hundred feet. All iPhone OS devices (iPhone, iPod Touch and iPad) support WiFi hotspot geolocation services.