You are on page 1of 10

maXbox Starter 39

Start with GEO Maps


1.1 Go with OpenStreetMap
Today we run through GEO Maps coding.
To find a street nowadays is easy; open a browser and search for.
One of the questions that comes up when encoding those coordinates is
how they can be useful in a script with for example in maXbox
OpenMapX('cathedral cologne');
OpenMapX('50.94134 6.95813'); //string!

!ith a G"# or na$igation The Global "ositioning #ystem %G"#& is a space'
based satellite na$igation system that pro$ides location and time
information in all weather conditions. (ut you need a map to $isuali)e.
Each G"# satellite continuously broadcasts a na$igation message at a
rate of *+ bits per second. , message ta-es .*+ seconds to complete/
#uch a record does ha$e as minimum na$i information
procedure GP!ecord
begin
"r#teln('t#$e%date%lat#t&de%long#t&de%alt#t&de%n'at%'peed%co&r'e');
end
This isn0t $ery different from a normal weather station cloc-1 isn0t it2 3ow
we define our map search to get the map in your standard browser. !e
use the mapquest ,"4 from
http55open.mapquestapi.com5nominatim5
The following example demonstrates a simple map search request for
67athedral 7ologne6 using the 3ominatim quest. Only three parameters
are being requested %menu (#e")G*O Map (#e"&
8. format ' Output format being called. 9html5:son5xml;
<. :son=callbac- ' 7allbac- function used to display results below.
>. q ' ?uery string being searched for.
!e set first a const in the script to send the request
Const
+M+P,-.*/+M*01 '$a2$ap3#le.ht$l';
4rlMap5&e't+P-6ode01'http788open.$ap9&e'tap#.co$8no$#nat#$8:18'earch
.php;3or$at1<'=>'on?call@acA1renderBa'#cearch/arrat#:e=91<'';
@ow are these > arguments lin-ed together
3or$at1<'
>'on?call@acA1renderBa'#cearch/arrat#:e
91<'
Aou0ll notice that the :son=callbac- parameter is already set. The format
and the query string indeed is up to you. !e use a html format to prepare
open a browser with the map1 se here0s the call
if GetM+PX('ht$l'%*2ePathC'cologne0$apX.ht$l'%'cathedral cologne')
then "r#teln('6ologne Map 3o&nd');
(y the way Most of G"# and data formats is found by the 3ME,.
The 3ME, is the 3ational Marine Electronics ,ssociation. 4t is to be a
worldwide1 self'sustaining organi)ation committed to enhancing the
technology and safety of electronics used in marine applications and you
see also a standard for G"# data formats.
@ow it wor-s The G"# satellites transmit signals to a G"# recei$er. These
recei$ers passi$ely recei$e those signals; they do not transmit and require
a clear $iew of the s-y1 so they can only be used effecti$ely outdoors1 or
from time to time in trains or gadgets;'&.
2
Type
D!ece#:e?,&nc 1 DGP.er#al!26har(ender7 TObject);
Bets bac- to our easy call
GetM+PX('ht$l'%*2ePathC'cologne0$apX.ht$l'%'cathedral cologne')
OpenMap('&@' ag @&rgdor3');
Aou also find a procedure with same meaning
GetGeoM+P('ht$l'%*2ePathC+M+P,-.*/+M*0%'do$ cologne')

3ote in both cases1 this code is assuming C<++. or earlier as maXbox
follows. 4n C<++D and later1 #tring is Enicode now1 so you need to -now
the Encoding of the Dtrea$ contents ahead of time in order for the bytes
to be interpretted as1 or con$erted to1 Enicode correctly.
Otherwise1 you would ha$e to change to operate on ,nsi#tring or the new
Faw(yte#tring instead.
1.1.1 The Dark side of the Code
Ob$iously the most important de$ice required for this software to wor-1 is
the map from the internet pro$ider OpenStreetMap. ,ll browser de$ices with
a Ga$a #cript E7M, compatible connection are supported.
The Ga$a #cript code which sends the request and displays the result can
be $iewed here as an XMB output for example
Test mX4 Ref: XML, JO!, "TML
Ere#ersegeocode t#$e'ta$p1FThu, $% ep $4 %&:'%:(% )&&&&F attr#@&t#on1F*+t+
, OpentreetM+p contributors, O*bL $-&-
http:..///-openstreetm+p-org.copyrightF
9&erG'tr#ng1Fform+t0htm12json3c+11b+c40render56+mp1eThreeResu1ts21+t047-&(8
79%:21on07-:%8$47:$%77999;<=resu1t p1+ce3id0F15100H59F osm3type0FnodeF
osm3id0F13H8H99500F ref0F4B +GF 1+t0F4H.03986H6F 1on0FH.6091404FI>? @A,
?+hnhofstr+sse, Oberst+dt, ?urgdorf, Ber/+1tungs4reis 5mment+1,
Ber/+1tungsregion 5mment+1COber++rg+u, ?ern, (4$4,
/itDer1+ndE8resu1tIE+ddressp+rtsIE+tmI>?
@AE8+tmIEro+dI?+hnhofstr+sseE8ro+dIEneighbourhoodIOberst+dtE8neighbourhoodI
Eto/nI?urgdorfE8to/nIEcountyIBer/+1tungs4reis
5mment+1E8countyIEst+te3districtIBer/+1tungsregion 5mment+1C
Ober++rg+uE8st+te3districtIEst+teI?ernE8st+teIEpostcodeI(4$4E8postcodeIEcou
ntryI/itDer1+ndE8countryIEcountry3codeIchE8country3codeI
E8+ddressp+rtsIE8re#ersegeocodeI
3
Hrom the result let0s go bac- to the code behind.
,s you already -now the tool is split up into the toolbar across the top1 the
editor or code part in the centre and the output window at the bottom.
7hange that in the menu 5$iew at our own style.
(efore this starter code will wor- you will need to download maXbox
from a website. Aou0ll get it from
http788""".'o3t"are'ch&le.ch8$a2@o2.ht$ . Once the download has
finished1 un)ip the file1 ma-ing sure that you preser$e the folder structure
as it is. Test it with F9 5 H< or press 7ompile and you should hear a test
sound. #o far so good now weIll open the examples
509?G*OMap3.t2t
4f you canIt find the two files try also direct as a file
http788""".'o3t"are'ch&le.ch8e2a$ple'8509?G*OMap3.t2t
3ow letIs ta-e a loo- at the code of this app. One of our first line is
creating the ob:ect $aptrea$ and the encoded EFB we use first methods
to configure our JDDPGet() calling "ort and 4" of the mapquest ,"4 with the
help of JDDP*ncode. The ob:ect ma-es a bind connection with the ,cti$e
method by passing an encoded EFB with a memory stream
procedure GetMapcr#pt(6?3or$%apath7 string; const Kata7string);
#+r enc4!.7 string;
$aptrea$7 DMe$orGtrea$;
begin
enc4!.71 ,or$at(4rlMap5&e't+P-6ode0% Lc?3or$%JDDP*ncode(Kata)M);
$aptrea$71 DMe$orGtrea$.create;
try
JttpGet(*nc4!.% $aptrea$); //WinInet
$aptrea$.Po'#t#on71 0;
$aptrea$.a:eto3#le(apath)
OpenKoc(apath);
fin+11y
$aptrea$.,ree;
end;
end;
The OpenKoc() procedure is used to get a browser open1 you remember
the call abo$e
GetM+Pcr#pt('ht$l'%*2ePathC'cologne0$apX.ht$l'%
'cathedral cologne')
,s we decode this with Hormat li-e abo$e
3or$at1ht$l
>'on?call@acA1renderBa'#cearch/arrat#:e
91cathedral cologne
,nd this is how another function with download wor-s

function GetMapXcr#pt(6?3or$%apath7 string; const Kata7 string)7 @oolean;


#+r encoded4!.7 string;
begin
encoded4!.71 ,or$at(4rlMap5&e't+P-6ode0%Lc?3or$%JDDP*ncode(Kata)M);
try
//instead HttpGet(EncodedURL, mapStream); //WinInet
!e'&lt71 >r1*o/n1o+dToEi1e(!i1%P6har(encoded4!.)%P6har(apath)%0%!i1)1 0;
OpenKoc(apath);
fin+11y
encoded4!.71 '';
end;
end;

This function is shorter than the first one because we use no streams in
between. !or-ing with streams in Hree "ascal or Celphi you ha$e to
include some units to be able to use or code your functions direct in the
script as you li-e
function Ko"nload,#le(o&rce,#le% Ke't,#le7 string)7 Boolean;
begin
//TCIStat!s T"indStat!s TURLTemp#ate o$ URL%on
try
!e'&lt71
>r1*o/n1o+dToEi1e(!i1%P6har(o&rce,#le)%P6har(Ke't,#le)%0%!i1)1 0;
e6cept
!e'&lt71 ,al'e;
end;
end;
!
4n maXbox those units and many others are pre'compiled and included on
demand. ,s long as the ,"4 is stable we don0t ha$e change calls.
4rlMap5&e't+P-6ode01'http788open.$ap9&e'tap#.co$8no$#nat#$8:18'earch
.php;3or$at1<'=>'on?call@acA1renderBa'#cearch/arrat#:e=91<'';

,fter these steps1 we can start with programming the rest of the GEO code
called re$erse GEO code.
Fe$erse geocoding is the process of bac- %re$erse& coding of a point
location %latitude1 longitude& to a readable address or place name.
GeoNames for ex. offers a wide range of re$erse geocoding web ser$ices.
This permits identification of nearby street addresses1 places1 stations
and5or areal subdi$isions such as county1 state or country.
8.8.< Fe$erse GEO 7ode
The interesting point is now that we store no data on a file we :ust use a
memory stream to get data direct on the console of maXbox.
Those data can be used with any console or script recei$er to ma-e further
in$estigations. This may howe$er $ary depending on what data sentence
the coordinates find or deli$ers1 for ex. the cathedral at cologne
"r#teln(GetMapXGeo!e:er'e('XM.'%'50.94134'%'6.95813'))
or more accurate
GetMapXGeo!e:er'e0('XM.'%topPath%'50.94133H05'%'6.95810611100H66')
then
E;2$l :er'#on1F1.0F encod#ng1F4D,N8F;I
CEre#ersegeocode
9&erG'tr#ng1Fform+t0XML2json3c+11b+c40render56+mp1eThreeResu1ts21+t0'&-84$(
(7&'21on0:-8'9$%:$$$&&7::; +ttribution0FKata O OpentreetMap contr#@&tor'%
OK@. 1.0. http:..///-openstreetm+p-org.copyrightF t#$e'ta$p1FMon, %% ep $4
$(:(::4( )&&&&FI
Eresu1t lon1F:-8'9$%:$$$&&7::F lat1F'&-84$((7&'F re31FFG1ner *omF
o'$?#d1F4'(%&%%F o'$?tGpe1F/+yF place?#d1F4&4&:488FIFG1ner *om, 4,
*om41oster, >rsu1+CBierte1, @1tst+dtC!ord, Hnnenst+dt, FG1n,
RegierungsbeDir4 FG1n, !ordrheinCIestf+1en, '&::7,
*eutsch1+ndE8resu1tIC
E+ddressp+rtsI
Ep1+ce3of3/orshipIFG1ner *omE8p1+ce3of3/orshipI
Ehouse3numberI4E8house3numberI
Epedestri+nI*om41osterE8pedestri+nI
EneighbourhoodI>rsu1+CBierte1E8neighbourhoodI
EsuburbI@1tst+dtC!ordE8suburbI
Ecity3districtIHnnenst+dtE8city3districtI
EcountyIFG1nE8countyI
Est+te3districtIRegierungsbeDir4 FG1nE8st+te3districtI
Est+teI!ordrheinCIestf+1enE8st+teI
EpostcodeI'&::7E8postcodeI
EcountryI*eutsch1+ndE8countryI
Ecountry3codeIdeE8country3codeI
E8+ddressp+rtsI
E8re#ersegeocodeI
"
Fe$erse geocoding can be carried out systematically by ser$ices which
process a coordinate similarly to a geocoding process.
Hor ex.1 when a G"# coordinate is entered the street address is interpol'
ated from a range assigned to the road segment in a reference dataset
that the point is nearest to.
o'$?#d1F4'(%&%%F o'$?tGpe1F/+yF place?#d1F4&4&:488FIFG1ner *om, 4,
*om41oster, >rsu1+CBierte1, @1tst+dtC!ord, Hnnenst+dt, FG1n,
RegierungsbeDir4 FG1n, !ordrheinCIestf+1en, '&::7,
*eutsch1+ndE8resu1tIC
Each table has a way column containing the geometry for the ob:ect in
the chosen pro:ection. Two indices are created for each table one for the
way column and one for the osm=id column1 see abo$e.
Geometry uses coordinates in the E"#GD++D8> ,J, G++GlE pro:ection
and can be easily used in e.g. OpenBayers based Ga$a#cript.
3ow for the code behind the call. !e need another mapquest ,"4 of the get
request ser$ice
4rlMap5&e't+P-371 'http788open.$ap9&e'tap#.co$8no$#nat#$8:18re:er'e.php;
3or$at1<'=>'on?call@acA1render*2a$pleDhree!e'&lt'=lat1<'=lon1<'';
,s you can see it0s a "@" ser$er side ser$ice
encoded4!.7
http788open.$ap9&e'tap#.co$8no$#nat#$8:18re:er'e.php;
The function maps a stream to a string and is similar to abo$e1 except we
don0t sa$e a file1 but you can sa$e the stream as an XMB or Gson file
$ap'trea$.'a:eto3#le(apath) and OpenKoc(apath);

function GetMapXGeo!e:er'e0(6?3or$%apath7 string; const lat%long7
string)7@oolean;
#+r encoded4!.% 4rlMap5&e't+P-% @&3'tr7 string;
$aptrea$7 DMe$orGtrea$;
begin
4rlMap5&e't+P-71 'http788open.$ap9&e'tap#.co$8no$#nat#$8:18re:er'e.php;
3or$at1<'=>'on?call@acA1render*2a$pleDhree!e'&lt'=lat1<'=lon1<'';
encoded4!.71 ,or$at(4rlMap5&e't+P-%Lc?3or$% lat% longM);
$aptrea$71 DMe$orGtrea$.create;
try
JttpGet(*ncoded4!.% $aptrea$); &WinInet'
$aptrea$.Po'#t#on71 0;
"r#teln(''trea$ '#Pe7 'C#ntto'tr($ap'trea$.'#Pe)); //mapStream(memor);
@&3'tr71 trea$Dotr#ng($ap'trea$);
"r#teln(''trea$ @acA7 'C@&3'tr)
fin+11y
encoded4!.71 '';
$aptrea$.,ree;
end;
end;
#
Two ways to map a stream to a string
8. Fead the a$ailable #i)e of the T#tream1 allocate a #tring of that length1
and then Fead%& the T#tream contents into the #tring
function trea$Dotr#ng0(trea$7 Dtrea$)7 tring;
#+r
len7 -nteger;
begin
len71 trea$.#Pe N trea$.Po'#t#on;
et.ength(!e'&lt% len);
if len I 0 then trea$.!eadB&33er(!e'&lt% len);
"r#teln('te't N @&33er read checAQ')
end;
<. 7reate an intermediate T#tring#tream1 7opyHrom%& the T#tream to the
T#tring#tream1 and then read the T#tring#tream.Cata#tring property
&code*ma+,o-'
function trea$Dotr#ng3(trea$7 Dtrea$)7 tring;
begin
/ith Dtr#ngtrea$.6reate('') do
try
6opG,ro$(trea$% trea$.#PeNtrea$.Po'#t#on);
!e'&lt71 Katatr#ng;
fin+11y
,ree;
end;
end;
DMe$orGtrea$ and D,#letrea$ are both decendants of Dtrea$ and
they wor- exactly the same way.
The problem 4 mostly found is that if we write one stream to another1 we
ha$e to reset the origins before using it again li-e
(M.eeA(0%'o,ro$Beg#nn#ng);.
,nother point is to direct test a pair of coordinates. Aou can also con$ert
coordinates %lat and long& to a map on the internet %,ppendix&.
http55www.gps'coordinates.net5
Aou can find the address corresponding to G"# coordinates or latitude1
longitude and address of any point on Open#treetMap.
@ope you did already wor- with the #tarter >K on G"# topics
http55sourceforge.net5p5maxbox5wi-imax5main5
,t least we see a picture o$er a distance of >LL -m. This image below is
my sight of a trac- the yellow line is the speed and the blue one mar-s
the altitude point.
$
Almanac data is data that describes the orbital courses of the satellites.
E$ery satellite will broadcast almanac data for EMEFA satellite. Aour G"#
recei$er uses this data to determine which satellites it expects to see in
the local s-y; then it can determine which satellites it should trac-.
1.2 GPS and Arduino Conclusion
4 would also recommend the boo- 6,rduino 7oo-boo-N by Michael
Margolis. @ere are a few ideas of more complicated pro:ects that 4 ha$e
seen made with an ,rduino.
O , box that will only open when it is at a certain location in the world %4t
connects a G"# to the ,rduino. #earch on 6Fe$erse Geo'cacheN to see
some examples.&
O Or a controller for a >C printer to print out the landscape the G"# or
OpenM+PX() has :ust scanned/
%eedba&k '
max'k(ei)er.&om
*iterat+re, -(ei)er et a(.. /atter)s ko)kret. 2003. Software 1 S+pport
http,22e).wikipedia.or32wiki24e5erse63eo&odi)3
http,22www.k(ei)er.&h2k(ei)er23psmax.htm
http55www.softwareschule.ch5examples5K.*=G"#=mX<.txt
tre+m Ref:
http:..emb+rc+dero-ne/sgroups-+rchi#ed-+t.pub1ic-de1phi-#c1-components-usin
g.%&&8&7.&8&7%8%77'-htm1
7 8rd+i)o Examp(e.
http,22www.softwares&h+(e.&h2dow)(oad28rd+i)o6C62016"6basta6box.pdf
http,22so+r&efor3e.)et2pro9e&ts2maxbox
9
1.3 Appendix Map Study
maXmap
DD :de&ima( de3rees;<
*atit+de $.#2!#= :$."!"2$09"3!""9!;
*o)3it+de #.132#E :".991$13"$9209$;
1 4+e d+ Ca)a(. !#0! G+)t>5i((er. %ra)&e
Latitude : $.#2!# ? Longitude : #.132# Altitude : 2$# meters
Jere another $ap 'earch Poo$ o3 OpenM+PX7
RTClock: Arduino by Silvia Rothen http://www.ecotronics.ch/ecotron/arduinocheatsheet.htm
10

You might also like