send last location to web with arduino

Hello everyone!
I am basic android developer, and i have a project calls vehicle tracking system with arduino.

i have not enough information about arduino but i programmed it successfully, it sends the location to the API however, it uses too much data and API not working very well due to the requests because there is an loop and the program send the location using a timer.

in android, we can implement GPS class has onLocationChanged method this method detects if the location changes. so, we can send the last location in this method and it is so useful because it does not use much ram and data. so here is an example of android

// Acquire a reference to the system Location Manager
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

// Define a listener that responds to location updates
LocationListener locationListener = new LocationListener() {
    public void onLocationChanged(Location location) {
      // Called when a new location is found by the network location provider.
     // so we can send the location now!
    }

    public void onStatusChanged(String provider, int status, Bundle extras) {}

    public void onProviderEnabled(String provider) {}

    public void onProviderDisabled(String provider) {}
  };

// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);

in arduino code there are many examples but usually they send the location in a loop so it is not useful for me Please help me about it is there any way, i can send the location if location change ?

Post your Arduino code not your Android location listener class from your app, your be told that this is not an Android forum.

any how you just need to implement a function in your Arduino code to check if the location has changed and i would still use your timer to send say every 5 seconds rather than just testing if the location has changed.

unsigned long currentMillis;
double latitude;
double longitude;

void setup() {

}

void loop() {
  sendLocation();
}

void sendLocation() {
  currentMillis = millis();
  static double previous_Latitude;
  static double previous_Longitude;
  const long interval = 5000;
  static unsigned long previousMillis = 0;
  if (currentMillis - previousMillis >= interval) {
    if (previous_Latitude != latitude || previous_Longitude != longitude) {
      // run some code to send the new location to the API
      // .....
      // .....
      // Lock out the function till the location has changed again
      previous_Latitude = latitude;
      previous_Longitude  = longitude;
    }
    previousMillis = currentMillis;
  }
}

Please read the post carefully and then answer it !!

i know, here is not an android forum ! i just gave an example in java to make my question can understandable.

Also i allready said "i have not enough information about arduino..." there is no c++ so i asked on this page

even if i write android code, does it going to make a problem for you ?

whats is your problem with another programming language ?

:frowning:

Wow.

whats is your problem with another programming language ?

None, IF the program language is appropriate. You can NOT program the Arduino in Java, so it is pointless to post Java code here.

It IS possible to determine the distance between the current location and the previous location. How difficult that is depends on the unposted code on the Arduino, and is completely independent of the crap on the Android.

It is trivial to determine that the distance is, or is not, greater than some threshold. If it is, send the current location and update the previous location with the current location.

PaulS:
None, IF the program language is appropriate. You can NOT program the Arduino in Java, so it is pointless to post Java code here.

It IS possible to determine the distance between the current location and the previous location. How difficult that is depends on the unposted code on the Arduino, and is completely independent of the crap on the Android.

It is trivial to determine that the distance is, or is not, greater than some threshold. If it is, send the current location and update the previous location with the current location.

as i said, i know, ardunio cannot be programmed with Java all i wanted to just give an example in java to explain my question.

and also thank you for your answer i will try it!