summaryrefslogtreecommitdiff
path: root/navit/coord.c
diff options
context:
space:
mode:
authorsteven_s <steven_s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2008-11-09 16:13:30 +0000
committersteven_s <steven_s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2008-11-09 16:13:30 +0000
commit8954e9545767cd8319e122d01ba5f51753d1f3ad (patch)
treebaa2bae9967cb6f7c2c4db921b909189bc08e08b /navit/coord.c
parent7442c65338e40a5742b835977f5cfe598aff5fda (diff)
downloadnavit-8954e9545767cd8319e122d01ba5f51753d1f3ad.tar.gz
Patch:core:Added geo coordinate formatting function that supports multiple formats |
Replacing local geoformatting with calls to this function. git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@1709 ffa7fe5e-494d-0410-b361-a75ebd5db220
Diffstat (limited to 'navit/coord.c')
-rw-r--r--navit/coord.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/navit/coord.c b/navit/coord.c
index 787934788..f74eb3267 100644
--- a/navit/coord.c
+++ b/navit/coord.c
@@ -280,4 +280,58 @@ coord_print(enum projection pro, struct coord *c, FILE *out) {
return;
}
+/**
+ * @brief Converts a lat/lon into a text formatted text string.
+ * @param lat The latitude
+ * @param lng The longitude
+ * @param fmt The format to use.
+ * @li DEGREES=>(45.5000N 100.9000S)
+ * @li DEGREES_MINUTES=>(45 30.))00N 100 120.54.0000S)
+ * @li DEGREES_MINUTES_SECONDS=>(4530.0000N 12054.0000S)
+ *
+ *
+ * @param buffer A buffer large enough to hold the output + a terminating NULL (26 bytes)
+ * @param size The size of the buffer
+ *
+ */
+void coord_format(float lat,float lng, enum coord_format fmt, char * buffer, int size)
+{
+
+ char lat_c='N';
+ char lng_c='E';
+ float lat_deg,lat_min,lat_sec;
+ float lng_deg,lng_min,lng_sec;
+
+ if (lng < 0) {
+ lng=-lng;
+ lng_c='W';
+ }
+ if (lat < 0) {
+ lat=-lat;
+ lat_c='S';
+ }
+ lat_deg=lat;
+ lat_min=(lat-floor(lat_deg))*60;
+ lat_sec=fmod(lat*3600,60);
+ lng_deg=lng;
+ lng_min=(lng-floor(lng_deg))*60;
+ lng_sec=fmod(lng*3600,60);
+ switch(fmt)
+ {
+
+ case DEGREES_DECIMAL:
+ snprintf(buffer,size,"%02.6f%c %03.7f%c",lat,lat_c,lng,lng_c);
+ break;
+ case DEGREES_MINUTES:
+ snprintf(buffer,size,"%02.0f %07.4f%c %03.0f %07.4f%c",floor(lat_deg),lat_min , lat_c, floor(lng), lng_min, lng_c);
+ break;
+ case DEGREES_MINUTES_SECONDS:
+ snprintf(buffer,size,"%02.0f%07.4f%c %03.0f%07.4f%c",floor(lat), fmod(lat*60,60), lat_c, floor(lng), fmod(lng*60,60), lng_c);
+ break;
+
+
+ }
+
+}
+
/** @} */