개발 가이드

Local Navigation

코드 샘플: BlackBerryLocationProvider 클래스를 사용하여 위치 추적 제어

import net.rim.device.api.gps.*;
import javax.microedition.location.*;
public class handleGPS
{
    static BlackBerryLocationProvider myProvider;
    public handleGPS()
    {
        try
        {
            BlackBerryCriteria myCriteria =
              new BlackBerryCriteria(GPSInfo.GPS_MODE_AUTONOMOUS);
            try
            {
                myProvider = (BlackBerryLocationProvider)
                  LocationProvider.getInstance(myCriteria);
                myProvider.setLocationListener(new handleGPSListener(), 10, -1, -1);
            }
            catch ( LocationException lex )
            {
                return;
            }
            myProvider.pauseLocationTracking(30);
            myProvider.resumeLocationTracking();
            myProvider.stopLocationTracking();
        }
        catch ( UnsupportedOperationException uoex )
        {
            return;
        }
        return;
    }
    public static class handleGPSListener implements LocationListener
    {
        public void locationUpdated(LocationProvider provider, Location location)
        {
            if (location.isValid())
            {
                // do something
            }
            else
            {
                // invalid location
            }
        }
        public void providerStateChanged(LocationProvider provider, int newState)
        {
            if (newState == LocationProvider.AVAILABLE)
            {
                // available
            }
            else if (newState == LocationProvider.OUT_OF_SERVICE)
            {
                // GPS unavailable due to IT policy specification
            }
            else if (newState == LocationProvider.TEMPORARILY_UNAVAILABLE )
            {
                // no GPS fix
            }
        }
    }
}

이 정보가 도움이 되었습니까? 의견을 보내 주십시오.