Search on geo-position
[geeqie.git] / doc / docbook / GuideReferenceDecodeLatLong.xml
1 <?xml version="1.0" encoding="utf-8"?>\r
2 <section id="GuideReferenceDecodeLatLong">\r
3   <title id="titleGuideReferenceDecodeLatLong">Decoding Latitude and Longitude</title>\r
4   <para>This section is relevent to the search option "Search on geo-location".</para>\r
5   <para>\r
6     The result of some internet or other searches for placenames can contain a latitude and longitude embedded in a text string. For example an openstreetmap.org search can give a URL such as:\r
7     <para />\r
8     <code>https://www.openstreetmap.org/search?query=51.5542%2C-0.1816#map=12/51.5542/-0.1818</code>\r
9   </para>\r
10   <para>\r
11     If you paste such a string into the search box, the latitude/longitude can be automatically extracted and used as the origin of the search. To do this create the file\r
12     <para />\r
13     <code>~/.config/geeqie/geocode-parameters.awk</code>\r
14     <para />\r
15     and copy the following text into it:\r
16   </para>\r
17   <para>\r
18     <programlisting xml:space="preserve">\r
19 # Store this file in:\r
20 # ~/.config/geeqie/geocode-parameters.awk\r
21 #\r
22 # This file is used by the Search option "search on geo-position".\r
23 # It is used to decode the results of internet or other searches\r
24 # to extract a geo-position from a text string. \r
25 # To include other searches, follow the examples below and\r
26 # ensure the returned value is either in the format:\r
27 # 89.123 179.123\r
28 # or\r
29 # Error: $0\r
30 #\r
31 \r
32 function check_parameters(latitude, longitude)\r
33     {\r
34     # Ensure the parameters are numbers    \r
35     if ((latitude == (latitude+0)) &amp;&amp; (longitude == (longitude+0)))\r
36         {\r
37         if (latitude &gt;= -90 &amp;&amp; latitude &lt;= 90 &amp;&amp;\r
38                         longitude &gt;= -180 &amp;&amp; longitude &lt;= 180)\r
39             {\r
40             return latitude " " longitude\r
41             }\r
42         else\r
43             {\r
44             return "Error: " latitude " " longitude\r
45             }\r
46         }\r
47     else\r
48         {\r
49         return "Error: " latitude " " longitude\r
50         }\r
51     }\r
52 \r
53 # This awk file is accessed by the decode_geo_parameters() function\r
54 # in search.c. The call is of the format:\r
55 # echo "string_to_be_searched" | awk -f geocode-parameters.awk\r
56 #\r
57 # Search the input string for known formats.\r
58 {\r
59 if (index($0, "http://www.geonames.org/maps/google_"))\r
60     {\r
61     # This is a drag-and-drop or copy-paste from a geonames.org search\r
62     # in the format e.g.\r
63     # http://www.geonames.org/maps/google_51.513_-0.092.html\r
64     \r
65     gsub(/http:\/\/www.geonames.org\/maps\/google_/, "")\r
66     gsub(/.html/, "")\r
67     gsub(/_/, " ")\r
68     print check_parameters($1, $2)\r
69     }\r
70 \r
71 else if (index($0, "https://www.openstreetmap.org/search?query="))\r
72     {\r
73     # This is a copy-paste from an openstreetmap.org search\r
74     # in the format e.g.\r
75     # https://www.openstreetmap.org/search?query=51.4878%2C-0.1353#map=11/51.4880/-0.1356\r
76     \r
77     gsub(/https:\/\/www.openstreetmap.org\/search\?query=/, "")\r
78     gsub(/#map=.*/, "")\r
79     gsub(/%2C/, " ")\r
80     print check_parameters($1, $2)\r
81     }\r
82 \r
83 else if (index($0, "https://www.openstreetmap.org/#map="))\r
84     {\r
85     # This is a copy-paste from an openstreetmap.org search\r
86     # in the format e.g.\r
87     # https://www.openstreetmap.org/#map=5/18.271/16.084\r
88     \r
89     gsub(/https:\/\/www.openstreetmap.org\/#map=[^\/]*/,"")\r
90     gsub(/\//," ")\r
91     print check_parameters($1, $2)\r
92     }\r
93 \r
94 else if (index($0, "https://www.google.com/maps/"))\r
95     {\r
96     # This is a copy-paste from a google.com maps search\r
97     # in the format e.g.\r
98     # https://www.google.com/maps/place/London,+UK/@51.5283064,-0.3824815,10z/data=....\r
99     \r
100     gsub(/https:\/\/www.google.com\/maps.*@/,"")\r
101     sub(/,/," ")\r
102     gsub(/,.*/,"")\r
103     print check_parameters($1, $2)\r
104     }\r
105 \r
106 else if (index($0,".html"))\r
107     {\r
108     # This is an unknown html address\r
109     \r
110     print "Error: " $0\r
111     }\r
112 \r
113 else if (index($0,"http"))\r
114     {\r
115     # This is an unknown html address\r
116     \r
117     print "Error: " $0\r
118     }\r
119 \r
120 else if (index($0, ","))\r
121     {\r
122     # This is assumed to be a simple lat/long of the format:\r
123     # 89.123,179.123\r
124     \r
125     split($0, latlong, ",")\r
126     print check_parameters(latlong[1], latlong[2])\r
127     }\r
128 \r
129 else\r
130     {\r
131     # This is assumed to be a simple lat/long of the format:\r
132     # 89.123 179.123\r
133     \r
134     split($0, latlong, " ")\r
135     print check_parameters(latlong[1], latlong[2])\r
136     }\r
137 }\r
138 \r
139     </programlisting>\r
140   </para>\r
141 </section>\r