Add:Tools:latlon2bookmark (utility to create a bookmark from coordinates). Thanks...
authorkazer_ <kazer_@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Thu, 14 Aug 2008 13:13:59 +0000 (13:13 +0000)
committerkazer_ <kazer_@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Thu, 14 Aug 2008 13:13:59 +0000 (13:13 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk/navit@1255 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/tools/latlon2bookmark.c [new file with mode: 0644]

diff --git a/navit/tools/latlon2bookmark.c b/navit/tools/latlon2bookmark.c
new file mode 100644 (file)
index 0000000..f7905ab
--- /dev/null
@@ -0,0 +1,121 @@
+/**\r
+ * this program is free software, please use it as you like.\r
+ * i am not a programmer, so please have this code reviewed\r
+ * to make sure it has nog bugs or ill side efects.\r
+ * use at your own risk\r
+ * compile it with: gcc -l m -o latlon2bookmark latlon2bookmark.c\r
+ * Credits for this work goes to edje in #navit\r
+**/\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <math.h>\r
+#include <string.h>\r
+\r
+int main( int argc, char **argv )\r
+{\r
+    char        description[256];\r
+    char        lngsign[10];\r
+    char        latsign[10];\r
+    float       lat;\r
+    float       lng;\r
+    long        intlat;\r
+    long        intlng;\r
+    int         i;\r
+    int         n;\r
+\r
+    if ( argc < 4 )\r
+     {\r
+     printf("\n");\r
+     printf("This program converts a lat/lon coordinates pair\n");\r
+     printf("into a bookmark you can use with navit.\n");\r
+     printf("This program expects 3 arguments in the following order:\n");\r
+     printf("Lat, Lon and a description\n");\r
+     printf("and will print a bookmark.\n");\r
+     printf("for example: latlon2bookmark 51.980344 4.358005 this is my house \n");\r
+     printf("\n");\r
+     return 1;\r
+     }\r
+\r
+    lat=atof(argv[1]);\r
+    lng=atof(argv[2]);\r
+\r
+    /* concatenate all parts of the description string */\r
+    strcpy(description, argv[3]);\r
+    n=0;\r
+    for (i=4; i < argc; i++)\r
+     {\r
+     /* add spaces between the parts of the description */\r
+     if ( i < argc )\r
+      {\r
+      strcat(description, " ");\r
+      }\r
+     strcat(description, argv[i]);\r
+     n=n+1;\r
+     }\r
+\r
+    if ( lat < -90 )\r
+     {\r
+     printf("\n");\r
+     printf("The first argument must be the lattitude\n");\r
+     printf("and can't be smaller then -90 (southpole)\n");\r
+     printf("\n");\r
+     return 2;\r
+     }\r
+\r
+    if ( lat > 90 )\r
+     {\r
+     printf("\n");\r
+     printf("The first argument must be the lattitude\n");\r
+     printf("and can't be bigger then 90 (northpole)\n");\r
+     printf("\n");\r
+     return 3;\r
+     }\r
+\r
+    if ( lng < -180 )\r
+     {\r
+     printf("\n");\r
+     printf("The second argument must be the longitude\n");\r
+     printf("and can't be smaller then -180 (oposite the 0 meridian)\n");\r
+     printf("\n");\r
+     return 4;\r
+     }\r
+\r
+    if ( lng > 180 )\r
+     {\r
+     printf("\n");\r
+     printf("The first argument must be the longitude\n");\r
+     printf("and can't be bigger then 180 (oposite the 0 meridian)\n");\r
+     printf("\n");\r
+     return 5;\r
+     }\r
+\r
+    /* convert the longitude to an integer */\r
+    intlng=lng*6371000.0*M_PI/180;\r
+\r
+    /* aparently if inlng < 0 , inlng needs to be inverted and a - sign used in the output */\r
+    strcpy(lngsign, "0x");\r
+    if ( intlng < 0)\r
+     {\r
+     intlng=(intlng ^ 0xffffffff);\r
+     strcpy(lngsign, "-0x");\r
+     }\r
+\r
+    /* and the same for the latitude */\r
+    intlat=log(tan(M_PI_4+lat*M_PI/360))*6371000.0;\r
+\r
+    /* aparently if inlat < 0 , inlat needs to be inverted and a - sign used in the output */\r
+    strcpy(latsign, "0x");\r
+    if ( intlat < 0)\r
+     {\r
+     intlat=(intlat ^ 0xffffffff);\r
+     strcpy(latsign, "-0x");\r
+     }\r
+\r
+    /* print the bookmark */\r
+    fprintf(stderr,"\n");\r
+    fprintf(stdout,"mg:%s%x %s%x type=bookmark label=\"%s\"\n",lngsign,intlng,latsign,intlat,description);\r
+    fprintf(stderr,"\n");\r
+\r
+    return 0;\r
+}\r