Class GPSView

  • All Implemented Interfaces:
    TimerListener

    public class GPSView
    extends Container
    implements TimerListener
    Control that display GPS coordinates read from the COM (or Bluetooth, or IR) port. In Windows Mobile and Android, it uses the native API instead of reading from the COM port. For example:
     add(gps = new GPSView(1000),LEFT,TOP);
     
    See the tc.samples.io.device.GPSTest. On Android, don't forget to turn on the GPS, going to Settings / Security & Location / Enable GPS satellites. The other platforms may require that as well. If the GPS fails connecting to the satellites, and the phone has signal, you can use the cell tower location as a rough location. The precision is vary between 50m to 3km, depending where the phone is. You can get the latitude and longitude using CellInfo.toCoordinates. This class uses the GPS class to show the values on Labels. You can use the GPS class standalone if you wish. See the tc.samples.maps.GoogleMaps sample.
    Since:
    TotalCross 1.38
    See Also:
    GPS, CellInfo.toCoordinates()
    • Field Detail

      • LON_LOW_SIGNAL

        public static java.lang.String LON_LOW_SIGNAL
        String that will be printed with there longitude can't be acquired. You can localize this string.
      • LAT_LOW_SIGNAL

        public static java.lang.String LAT_LOW_SIGNAL
        String that will be printed with there longitude can't be acquired. You can localize this string.
      • gps

        public GPS gps
        Class used to retrieve the GPS coordinates.
    • Constructor Detail

      • GPSView

        public GPSView()
                throws IOException
        Constructs a GPS using a read interval of 2 seconds.
        Throws:
        IOException
      • GPSView

        public GPSView​(int readInterval)
                throws IOException
        Constructs a GPSView using the given read interval.
        Parameters:
        readInterval - The interval used to fetch data, in milliseconds. A ControlEvent.PRESSED is posted each time the TRIGGERED event occurs.
        Throws:
        IOException
      • GPSView

        public GPSView​(PortConnector sp,
                       int readInterval)
                throws IOException
        Constructs a GPSView using the given PortConnector and read interval. In Android and Windows Mobile, you should use the other constructor. #GPSView(int)
        Throws:
        IOException
      • GPSView

        public GPSView​(GPS gps,
                       int readInterval)
                throws IOException
        Constructs a GPSView using the given GPS as input.
        Throws:
        IOException
        Since:
        TotalCross 1.5
    • Method Detail

      • initUI

        public void initUI()
        Description copied from class: Container
        Called to initialize the User Interface of this container. This differs from the onAddAgain method by that this method is called only once, at the first time the control is added to the parent. When the container is being setup, the initUI method is called; then, the onAddAgain is called every time the container is added again.
        Overrides:
        initUI in class Container
      • retrieveGPSData

        public void retrieveGPSData()
        Retrieves the GPS data and updates the fields with it.
      • getPreferredWidth

        public int getPreferredWidth()
        Description copied from class: Control
        Returns the preferred width of this control.
        Overrides:
        getPreferredWidth in class Control
      • getPreferredHeight

        public int getPreferredHeight()
        Description copied from class: Control
        Returns the preferred height of this control.
        Overrides:
        getPreferredHeight in class Control
      • onColorsChanged

        protected void onColorsChanged​(boolean colorsChanged)
        Description copied from class: Control
        Called after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container. If colorsChanged is true, it was called from setForeColor/setBackColor/Container.add; otherwise, it was called from setEnabled
        Overrides:
        onColorsChanged in class Container
      • onFontChanged

        protected void onFontChanged()
        Description copied from class: Control
        Called after a setFont
        Overrides:
        onFontChanged in class Control