Android Community
Results 1 to 2 of 2

Thread: Android GPS support and info

  1. #1
    Join Date
    Nov 2007
    Posts
    81

    Default Android GPS support and info


    Q. Android should support built-in location-detection support such as common API to access the phone's GPS --- right? Is that the "Location Manager"?

    A. Android support does include Location-Based Services. More
    information about that API here: http://code.google.com/android/toolbox/apis/lbs.html

    Location-based Service APIs


    The Android SDK includes two packages android.location and com.google.android.maps that provide an initial look at the support in the Android platform for building location-based services. As with the entire SDK, this is an early look at these APIs, so there likely are gaps in functionality and documentation that will be filled out in future builds of the SDK. But in the spirit of releasing early and often, we're releasing these APIs for consumption and feedback. Please read on below for a brief introduction to each package, as well as a list of known issues.
    android.location

    Overview

    android.location is the package that contains several classes related to location services in the Android platform. It introduces the LocationManager system service, which provides an API to determine location and bearing if the underlying device supports it. The LocationManager should not be instantiated directly, but rather a handle to it should be retrieved via a call to Context.getSystemService(Context.LOCATION_SERVICE) .
    Once your application has a handle to the LocationManager, your application will be able to do three things:
    • Query for the list of all LocationProviders known to the LocationManager for its last known location.
    • Register/unregister for periodic updates of current location from a LocationProvider (specified either by Criteria or name).
    • Register/unregister for a given Intent to be fired if the device comes within a given proximity (specified by radius in meters) of a given lat/long.
    Creating mock LocationProviders

    For testing purposes, developers can also create mock LocationProviders as follows. These canned LocationProviders will override any real LocationProvider of the same name.
    Each canned LocationProvider to be created needs a directory in the following location: /data/misc/location/<provider_name>.
    The canned LocationProvider instantiation searches its directory for the following files (in order):
    • class
    • kml
    • nmea
    • track
    A mock GPS provider can be found on the emulator in /data/misc/location/gps/.

    If class is present, then the class named on the first line within the file is instantiated and the result is installed as a provider.

    If a kml file is present, it is parsed for <coordinates> tags. The text within this tag looks like:

    <longitude>,<latitude>,<altitude> <longitude>,<latitude>,<altitude>
    <longitude>,<latitude>,<altitude> <longitude>,<latitude>,<altitude>

    The tags are concatenated to create a route. The speed of travel along the route may be controlled using the properties file (see below).

    One way to generate a suitable KML file is to get directions in Google Earth. Right-click the "Route" entry that appears at the end of the sequence of turns and select "Save as..." with "Save as type:" set to "Kml *(*.kml)".

    If no kml file is found, and an nmea file is present, it is parsed for NMEA 0183 sentences. Currently only $GPRMC sentences are fully supported; most GPS units should emit these sentences. The first timestamp encountered in the NMEA file is used as a base time, which is subtracted from the other timestamps to obtain a time delta which is interpreted relative to the time when the file was parsed.

    If no kml or nmea files are found, and a track file is present, it is parsed for lines of the form:

    <time> <longitude> <latitude> <altitude>

    or:

    <time> <longitude> <latitude> <altitude> <bearing> <speed>

    The times should start with 0, and are interpreted relative to the time when the file was parsed. The bearing (if present) is given in degrees clockwise from north, and the speed (if present) is given in meters per second.

    If a kml, nmea, or track file was read, the remaining properties of the LocationProvider can be specified in a properties file. Each line of the properties file has a key and an optional value. If the value is omitted, it defaults to true for boolean values and 0 for integer values. The key/value pairs are:

    requiresNetwork
    <boolean>

    requiresSatellite
    <boolean>

    requiresCell
    <boolean>

    hasMonetaryCost
    <boolean>

    supportsAltitude
    <boolean>

    supportsBearing
    <boolean>

    supportsSpeed
    <boolean>

    repeat
    <boolean> (track oscillates from start to end back to start)

    powerRequirement
    <integer> (1 = low, 2 = medium, 3 = high)

    accuracy
    <integer> (meters) trackSpeed <integer> (km/hour, only used for kml tracks)

    The altitude, speed, and/or bearing are reported only if the properties file sets hasAltitude, hasBearing, and hasSpeed to true.

    Known Issues with android.location

    By default, the LocationManager currently provides a single LocationProvider called "gps" that simulates a journey between two locations in the San Francisco Bay Area.

    com.google.android.maps

    Overview

    com.google.android.maps introduces a number of classes related to rendering, controlling, and overlaying other information on Google Maps. If you want to display a MapView in your application, note that the Activity that contains a MapView must be a subclass of MapActivity.

    Once you've created a MapView, you'll probably want to look at the getController() and getOverlayController() methods provided by MapView if you want to control the MapView itself or overlay additional information on the current MapView.

    For some more details about MapView and how it relates to MapView, please read the MapView section on the Google APIs and Services page.

    Known Issues with com.google.android.maps
    • Some methods (e.g. zoomTo(), zoomToSpan(), reset(), getOverlays()) need better docs and/or are subject to being renamed
    • Overlay event handling and the focus mechanism for Overlays have not been fully implemented
    • Some problems have been reported with Overlays not drawing

  2. #2
    Join Date
    Feb 2008
    Posts
    1

    Default


    Could you provide some example about how to initialize the LocationManager and how to use the GPS in application?

    I just read about the LocationManager seems need to define Context.getSystemService(Context.LOCATION_SERVICE) to obtain the GPS instance in the phone?

    So does it automate update or do I need to create a PROXY class to retrieve the newest update on GPS run repeatly?

    Please Provide a simplest example is a great Thanks
    Last edited by jackura; 02-26-2008 at 03:13 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •