Libraries \ NMEA

Reference for Wiring version 1.0 Build 0100+ If you have a previous version, use the reference included with your software. If see any errors or have any comments, let us know.

Class

NMEA

Name

gprmc_distance_to()

Examples
#include <nmea.h>

NMEA gps(GPRMC);  // GPS data connection to GPRMC sentence type

// destination coordinates in degrees-decimal
float dest_latitude = 48.858342;
float dest_longitude = 2.294522;

void setup() {
  Serial1.begin(4800);
  pinMode(8, OUTPUT);
}

void loop() {
  if (Serial1.available() > 0 ) {
    // read incoming character from GPS
    char c = Serial1.read();

    // check if the character completes a valid GPS sentence
    if (gps.decode(c)) {
      // check if GPS positioning was active
      if (gps.gprmc_status() == 'A') {
        // read distance to destination in meters and set led accordingly
        if (gps.gprmc_distance_to(dest_latitude, dest_longitude, MTR) < 500.0) {
          digitalWrite(8, HIGH);
        } else {
          digitalWrite(8, LOW);
        }
      }
    }
  }
}
Description Returns distance of the GPS to a given position. For example, your distance in meters to the Dom Tower in Utrecht (Netherlands), is given by gprmc_distance_to(52.090647, 5.121283, MTR). As units of distance, you can use MTR for meters, KM for kilometers, MI for (international) miles, and NM for nautical miles. Distance is calculated as 'great-circle distance' on a perfect sphere. It does not take into account terrain height variations, and Earth is no perfect sphere. As a result, calculated distance may be slightly off by an estimated maximum of 0.5%.
Syntax
gprmc_distance_to(latitude, longitude, unit)
Parameters
latitude float
longitude float
unit MTR, KM, MI, or NM
Returns float
Usage Application
Updated on July 07, 2011 11:11:09pm PDT

Creative Commons License