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