FileDocCategorySizeDatePackage
PlatformLocationProvider.javaAPI DocphoneME MR2 API (J2ME)15661Wed May 02 18:00:40 BST 2007com.sun.j2me.location

PlatformLocationProvider

public class PlatformLocationProvider extends LocationProviderImpl
Implementation of Location Provider.

Fields Summary
private String
providerName
The name of Location Provider
private int
provider
The handler of Location Provider
private static final int
MAX_LOCATION_BUFEER_SIZE
max size of Location Info in bytes
private static byte[]
lastKnownLocationBuffer
Input buffer for retrieve Location Info
LocationProviderInfo
providerInfo
Location Provider properties
private int
i3testProviderState
I3Test variable - provider state
private LocationImpl
i3testLocation
I3Test location - last location
Constructors Summary
public PlatformLocationProvider(String name)

 /* undefined by default */
     
     
    // JAVADOC COMMENT ELIDED
         
        /* open connection to the provider */
        provider = open(name);

        if (provider == 0) {
            throw new IllegalAccessException("Provider " + name + 
                    " is not supported");
        }
            
        /* create and fill criteria */
        if (getCriteria(name, providerInfo)) {
            criteria.setHorizontalAccuracy(providerInfo.horizontalAccuracy);
            criteria.setVerticalAccuracy(providerInfo.verticalAccuracy);
            criteria.setPreferredResponseTime(providerInfo.averageResponseTime);
            criteria.setPreferredPowerConsumption(
                    providerInfo.powerConsumption);
            criteria.setCostAllowed(providerInfo.incurCost);
            criteria.setSpeedAndCourseRequired(
                    providerInfo.canReportSpeedCource);
            criteria.setAltitudeRequired(providerInfo.canReportAltitude);
            criteria.setAddressInfoRequired(providerInfo.canReportAddressInfo);
        }
    
Methods Summary
protected native voidfinalize()

private native booleangetCriteria(java.lang.String name, com.sun.j2me.location.LocationProviderInfo criteria)

public intgetDefaultInterval()

        return (providerInfo.defaultInterval >= 1000) ?
            (providerInfo.defaultInterval / 1000) : 1;
    
public intgetDefaultMaxAge()

        return (providerInfo.defaultMaxAge >= 1000) ?
            (providerInfo.defaultMaxAge / 1000) : 1;
    
public intgetDefaultTimeout()

        return (providerInfo.defaultTimeout >= 1000) ?
            (providerInfo.defaultTimeout / 1000) : 1;
    
public static synchronized LocationgetLastKnownLocation()

        LocationInfo locationInfo = new LocationInfo();
        if (getLastKnownLocationImpl(locationInfo)) {
            return  locationInfo2Location(locationInfo);
        }
        return null;
    
private static native booleangetLastKnownLocationImpl(com.sun.j2me.location.LocationInfo locationInfo)

public synchronized LocationImplgetLastLocation()

        LocationInfo locationInfo = new LocationInfo();
        LocationImpl location = null;
        
        if (getLastLocationImpl(provider, locationInfo)) {
            location = locationInfo2Location(locationInfo);
        }
        return location;
    
private native booleangetLastLocationImpl(int provider, com.sun.j2me.location.LocationInfo locationInfo)

static native java.lang.StringgetListOfLocationProviders()

LocationImplgetNewLocationImpl(long timestamp)

        if (receiveNewLocationImpl(provider, timestamp)) {
            return getLastLocation();
        }
        return null;
    
public intgetResponseTime()

        return (providerInfo.averageResponseTime >= 1000) ?
            (providerInfo.averageResponseTime / 1000) : 1;
    
public intgetState()

        /* I3Test use only */
        if (i3testProviderState != 0) {
            return i3testProviderState;
        }
        /* Real mode */
        return getStateImpl(provider);
    
private native intgetStateImpl(int provider)

public intgetStateInterval()

        return (providerInfo.defaultStateInterval >= 1000) ?
            (providerInfo.defaultStateInterval / 1000) : 1;
    
voidi3test_setLocation(LocationImpl location)
Set Last Location I3test use only !!!

param
location

        i3testLocation = location;
    
voidi3test_setState(int newState)
Set provider state. I3test use only !!!

param
newState new state of Location Provider

        i3testProviderState = newState;
    
private static LocationImpllocationInfo2Location(com.sun.j2me.location.LocationInfo locationInfo)

        QualifiedCoordinates coordinates = new QualifiedCoordinates(
                locationInfo.latitude, locationInfo.longitude,
                locationInfo.altitude, locationInfo.horizontalAccuracy,
                locationInfo.verticalAccuracy);

        AddressInfo address = new AddressInfo();

        if (locationInfo.isAddressInfo) {
            if (locationInfo.AddressInfo_EXTENSION != null) {
                address.setField(AddressInfo.EXTENSION, 
                        locationInfo.AddressInfo_EXTENSION);
            }
            if (locationInfo.AddressInfo_STREET != null) {
                address.setField(AddressInfo.STREET, 
                        locationInfo.AddressInfo_STREET);
            }
            if (locationInfo.AddressInfo_POSTAL_CODE != null) {
                address.setField(AddressInfo.POSTAL_CODE, 
                        locationInfo.AddressInfo_POSTAL_CODE);
            }
            if (locationInfo.AddressInfo_CITY != null) {
                address.setField(AddressInfo.CITY, 
                        locationInfo.AddressInfo_CITY);
            }
            if (locationInfo.AddressInfo_COUNTY != null) {
                address.setField(AddressInfo.COUNTY, 
                        locationInfo.AddressInfo_COUNTY);
            }
            if (locationInfo.AddressInfo_STATE != null) {
                address.setField(AddressInfo.STATE, 
                        locationInfo.AddressInfo_STATE);
            }
            if (locationInfo.AddressInfo_COUNTRY != null) {
                address.setField(AddressInfo.COUNTRY, 
                        locationInfo.AddressInfo_COUNTRY);
            }
            if (locationInfo.AddressInfo_COUNTRY_CODE != null) {
                address.setField(AddressInfo.COUNTRY_CODE, 
                        locationInfo.AddressInfo_COUNTRY_CODE);
            }
            if (locationInfo.AddressInfo_DISTRICT != null) {
                address.setField(AddressInfo.DISTRICT, 
                        locationInfo.AddressInfo_DISTRICT);
            }
            if (locationInfo.AddressInfo_BUILDING_NAME != null) {
                address.setField(AddressInfo.BUILDING_NAME, 
                        locationInfo.AddressInfo_BUILDING_NAME);
            }
            if (locationInfo.AddressInfo_BUILDING_FLOOR != null) {
                address.setField(AddressInfo.BUILDING_FLOOR, 
                        locationInfo.AddressInfo_BUILDING_FLOOR);
            }
            if (locationInfo.AddressInfo_BUILDING_ROOM != null) {
                address.setField(AddressInfo.BUILDING_ROOM, 
                        locationInfo.AddressInfo_BUILDING_ROOM);
            }
            if (locationInfo.AddressInfo_BUILDING_ZONE != null) {
                address.setField(AddressInfo.BUILDING_ZONE, 
                        locationInfo.AddressInfo_BUILDING_ZONE);
            }
            if (locationInfo.AddressInfo_CROSSING1 != null) {
                address.setField(AddressInfo.CROSSING1, 
                        locationInfo.AddressInfo_CROSSING1);
            }
            if (locationInfo.AddressInfo_CROSSING2 != null) {
                address.setField(AddressInfo.CROSSING2, 
                        locationInfo.AddressInfo_CROSSING2);
            }
            if (locationInfo.AddressInfo_URL != null) {
                address.setField(AddressInfo.URL, 
                        locationInfo.AddressInfo_URL);
            }
            if (locationInfo.AddressInfo_PHONE_NUMBER != null) {
                address.setField(AddressInfo.PHONE_NUMBER, 
                        locationInfo.AddressInfo_PHONE_NUMBER);
            }
        }
        LocationImpl location = new LocationImpl(coordinates, locationInfo.speed,
             locationInfo.course, locationInfo.method, address,
             locationInfo.isValid);
        location.extraInfoNMEA  = locationInfo.extraInfoNMEA;
        location.extraInfoLIF   = locationInfo.extraInfoLIF;
        location.extraInfoPlain = locationInfo.extraInfoPlain;
        location.extraInfoOther = locationInfo.extraInfoOther;
        location.extraInfoOtherMIMEType = locationInfo.extraInfoOtherMIMEType;
        location.setTimestamp(locationInfo.timestamp);        
        return location;
    
private native intopen(java.lang.String name)

private native booleanreceiveNewLocationImpl(int provider, long timestamp)

public voidreset()

        resetImpl(provider);
        super.reset();
    
private native voidresetImpl(int provider)

protected LocationImplupdateLocation(long timeout)

        LocationImpl location = null;
        
        /* request location update */
        long startTimestamp = System.currentTimeMillis();
        if (i3testLocation == null) {
            if (waitForNewLocation(provider, timeout)) {
                /* get location and calculate timestamp  */
                long endTimestamp = System.currentTimeMillis();
                long timestamp = 
                        endTimestamp - providerInfo.averageResponseTime;
                if (timestamp < startTimestamp) {
                    timestamp = endTimestamp;
                }
                location = getNewLocationImpl(timestamp);
            }
        } else {
            location = i3testLocation;
        }
        return location;
    
private native booleanwaitForNewLocation(int provider, long timeout)