Home > Articles > Web Development > Dreamweaver & Flash

  • Print
  • + Share This
This chapter is from the book

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

  • orange-circle-1.jpg Create a new iPhone App, apply the appropriate certificates and profiles, and then save your file with the name iPhoneGeolocation.fla.
  • orange-circle-2.jpg Add a dynamic Classic Text box to the Stage with the name myTxt, and then apply the _Sans font.
  • orange-circle-3.jpg Create a new Class for the App with the name iPhoneGeolocation.
  • orange-circle-4.jpg Save the ActionScript file with the name iPhoneGeolocation.as.
  • orange-circle-5.jpg Add code to import the class files that allow you to use the Geolocation objects:
    import flash.events.GeolocationEvent;
    import flash.sensors.Geolocation
    
  • orange-circle-6.jpg Create a new geolocation variable that you can use:
    private var myGeo:Geolocation;
    
  • orange-circle-7.jpg 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.

  • orange-circle-8.jpg Add a function triggered by the geolocation listener: Publish and package your file into an iPhone App and test it on your iPhone.
  • orange-circle-9.jpg 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.

  • + Share This
  • 🔖 Save To Your Account