コード例 #1
0
ファイル: GpsHelper.java プロジェクト: conaxstore/GpsTracker
 private void createLocationListener() {
   // 2cd value is interval in seconds
   try {
     locationProvider.setLocationListener(this, interval, -1, -1);
   } catch (Exception e) {
     midlet.log("GPS.createLocationListener: " + e);
   }
 }
コード例 #2
0
ファイル: GpsHelper.java プロジェクト: conaxstore/GpsTracker
  private void createLocationProvider() {
    Criteria cr = new Criteria();

    try {
      locationProvider = LocationProvider.getInstance(cr);
    } catch (Exception e) {
      midlet.log("GPS.createLocationProvider: " + e);
    }
  }
コード例 #3
0
ファイル: GpsHelper.java プロジェクト: conaxstore/GpsTracker
  public void locationUpdated(LocationProvider provider, final Location location) {
    // get new location from locationProvider

    try {
      Thread getLocationThread =
          new Thread() {
            public void run() {
              sendLocationToWebsite(location);
            }
          };

      getLocationThread.start();
    } catch (Exception e) {
      midlet.log("GPS.locationUpdated: " + e);
    }
  }
コード例 #4
0
ファイル: GpsHelper.java プロジェクト: conaxstore/GpsTracker
  private void sendLocationToWebsite(Location location) {
    float speed = 0;

    try {
      QualifiedCoordinates qualifiedCoordinates = location.getQualifiedCoordinates();

      qualifiedCoordinates.getLatitude();

      if (oldCoordinates == null) {
        oldCoordinates =
            new Coordinates(
                qualifiedCoordinates.getLatitude(),
                qualifiedCoordinates.getLongitude(),
                qualifiedCoordinates.getAltitude());
      } else {
        if (!Float.isNaN(qualifiedCoordinates.distance(oldCoordinates))) {
          distance += qualifiedCoordinates.distance(oldCoordinates);
        }

        currentCoordinates =
            new Coordinates(
                qualifiedCoordinates.getLatitude(),
                qualifiedCoordinates.getLongitude(),
                qualifiedCoordinates.getAltitude());
        azimuth = (int) oldCoordinates.azimuthTo(currentCoordinates);
        oldCoordinates.setAltitude(qualifiedCoordinates.getAltitude());
        oldCoordinates.setLatitude(qualifiedCoordinates.getLatitude());
        oldCoordinates.setLongitude(qualifiedCoordinates.getLongitude());
      }

      if (qualifiedCoordinates != null) {
        // we are trying to get mySql datetime in the following format with a space (%20)
        // 2008-04-17%2012:07:02

        Calendar currentTime = Calendar.getInstance();
        StringBuffer mySqlDateTimeString = new StringBuffer();
        mySqlDateTimeString.append(currentTime.get(Calendar.YEAR)).append("-");
        mySqlDateTimeString.append(currentTime.get(Calendar.MONTH) + 1).append("-");
        mySqlDateTimeString.append(currentTime.get(Calendar.DATE)).append("%20");
        mySqlDateTimeString.append(currentTime.get(Calendar.HOUR_OF_DAY)).append(':');
        mySqlDateTimeString.append(currentTime.get(Calendar.MINUTE)).append(':');
        mySqlDateTimeString.append(currentTime.get(Calendar.SECOND));

        if (!Float.isNaN(location.getSpeed())) {
          speed = location.getSpeed();
        }

        String gpsData =
            "latitude="
                + String.valueOf(qualifiedCoordinates.getLatitude())
                + "&longitude="
                + String.valueOf(qualifiedCoordinates.getLongitude())
                + "&speed="
                + String.valueOf((int) (speed / 1609 * 3600)) // in miles per hour
                + "&direction="
                + String.valueOf(azimuth)
                + "&date="
                + mySqlDateTimeString
                + "&locationmethod="
                + location.getLocationMethod()
                + "&distance="
                + String.valueOf((int) (distance / 1609)) // in miles
                + "&username=javaMeUser"
                + "&phonenumber=867-5309"
                + "&sessionid="
                + String.valueOf(sessionID) // System.currentTimeMillis();
                + "&accuracy="
                + String.valueOf((int) (qualifiedCoordinates.getHorizontalAccuracy())) // in meters
                + "&extrainfo="
                + location.getExtraInfo("text/plain")
                + "&eventtype=javaMe";

        // with our query string built, we create a networker object to send the
        // gps data to our website and update the DB
        NetWorker netWorker = new NetWorker(midlet, uploadWebsite);
        netWorker.postGpsData(gpsData);
      }

    } catch (Exception e) {
      midlet.log("GPS.getLocation: " + e);
    }
  }