This code places an Elementary map widget on a window, to exemplify part of the widget\textquotesingle{}s API, related routes and names.

In this example, we will suppose we need to set a route for the user from his current point (a gps could provide us this information) to somewhere else. So we would have coordinates of this start point, and would like that he enters the address of his destination in a entry, and we\textquotesingle{}ll trace a route on the map.

We\textquotesingle{}ll start this example in the same way \mbox{\hyperlink{map_example_01}{Map Example 1}}. Adding a map with buttons to control zoom, so if you didn\textquotesingle{}t read it yet, just do it now. Actually there is a change, that we\textquotesingle{}re aligning buttons to the top, since we want a vertical control box this time.  
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ map\ =\ \mbox{\hyperlink{group__Elm__Map__Group_ga8f7fccd89ea054fe6e1202fe9a683091}{elm\_map\_add}}(win);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_ga9379629ad8ad2860aa786d838a4a106a}{evas\_object\_size\_hint\_weight\_set}}(map,\ \mbox{\hyperlink{Evas__Common_8h_aa47c85083d3dae0111c21ec49359306a}{EVAS\_HINT\_EXPAND}},\ \mbox{\hyperlink{Evas__Common_8h_aa47c85083d3dae0111c21ec49359306a}{EVAS\_HINT\_EXPAND}});}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Win__Group_ga505d6bd217e5ee01e82b548ec35986eb}{elm\_win\_resize\_object\_add}}(win,\ map);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga07208fcafd4739de606bc35fff684bf5}{evas\_object\_show}}(map);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ box\ =\ \mbox{\hyperlink{group__Elm__Box__Group_ga49ec615c90bf8bead2158d5ffab2e445}{elm\_box\_add}}(win);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Box__Group_ga447f790a64a49b477019938dc3d5c3ff}{elm\_box\_horizontal\_set}}(box,\ \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}});}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_ga9379629ad8ad2860aa786d838a4a106a}{evas\_object\_size\_hint\_weight\_set}}(box,\ \mbox{\hyperlink{Evas__Common_8h_aa47c85083d3dae0111c21ec49359306a}{EVAS\_HINT\_EXPAND}},\ \mbox{\hyperlink{Evas__Common_8h_aa47c85083d3dae0111c21ec49359306a}{EVAS\_HINT\_EXPAND}});}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Win__Group_ga505d6bd217e5ee01e82b548ec35986eb}{elm\_win\_resize\_object\_add}}(win,\ box);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga07208fcafd4739de606bc35fff684bf5}{evas\_object\_show}}(box);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ bt\ =\ \mbox{\hyperlink{group__Elm__Button_gaf5caf46d74c4e122a18da323935d25e4}{elm\_button\_add}}(win);}
\DoxyCodeLine{\ \ \ elm\_object\_text\_set(bt,\ \textcolor{stringliteral}{"{}+"{}});}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Box__Group_ga66a10dd861578521af2ab7b8c2ca65c5}{elm\_box\_pack\_end}}(box,\ bt);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga07208fcafd4739de606bc35fff684bf5}{evas\_object\_show}}(bt);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Smart__Object__Group_gac12dd6655f488cc47ce6cf00eb7d12b2}{evas\_object\_smart\_callback\_add}}(bt,\ \textcolor{stringliteral}{"{}clicked"{}},\ \_bt\_zoom\_in,\ map);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_gaaf1d3e26e36b316977336066b6f56632}{evas\_object\_size\_hint\_align\_set}}(bt,\ \mbox{\hyperlink{Evas__Common_8h_aecbac710f36d52911fc34dcdaf8e729c}{EVAS\_HINT\_FILL}},\ 0);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ bt\ =\ \mbox{\hyperlink{group__Elm__Button_gaf5caf46d74c4e122a18da323935d25e4}{elm\_button\_add}}(win);}
\DoxyCodeLine{\ \ \ elm\_object\_text\_set(bt,\ \textcolor{stringliteral}{"{}-\/"{}});}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Box__Group_ga66a10dd861578521af2ab7b8c2ca65c5}{elm\_box\_pack\_end}}(box,\ bt);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga07208fcafd4739de606bc35fff684bf5}{evas\_object\_show}}(bt);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Smart__Object__Group_gac12dd6655f488cc47ce6cf00eb7d12b2}{evas\_object\_smart\_callback\_add}}(bt,\ \textcolor{stringliteral}{"{}clicked"{}},\ \_bt\_zoom\_out,\ map);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_gaaf1d3e26e36b316977336066b6f56632}{evas\_object\_size\_hint\_align\_set}}(bt,\ \mbox{\hyperlink{Evas__Common_8h_aecbac710f36d52911fc34dcdaf8e729c}{EVAS\_HINT\_FILL}},\ 0);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ bt\ =\ \mbox{\hyperlink{group__Elm__Button_gaf5caf46d74c4e122a18da323935d25e4}{elm\_button\_add}}(win);}
\DoxyCodeLine{\ \ \ elm\_object\_text\_set(bt,\ \textcolor{stringliteral}{"{}X"{}});}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Box__Group_ga66a10dd861578521af2ab7b8c2ca65c5}{elm\_box\_pack\_end}}(box,\ bt);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga07208fcafd4739de606bc35fff684bf5}{evas\_object\_show}}(bt);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Smart__Object__Group_gac12dd6655f488cc47ce6cf00eb7d12b2}{evas\_object\_smart\_callback\_add}}(bt,\ \textcolor{stringliteral}{"{}clicked"{}},\ \_bt\_zoom\_fit,\ map);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_gaaf1d3e26e36b316977336066b6f56632}{evas\_object\_size\_hint\_align\_set}}(bt,\ \mbox{\hyperlink{Evas__Common_8h_aecbac710f36d52911fc34dcdaf8e729c}{EVAS\_HINT\_FILL}},\ 0);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ bt\ =\ \mbox{\hyperlink{group__Elm__Button_gaf5caf46d74c4e122a18da323935d25e4}{elm\_button\_add}}(win);}
\DoxyCodeLine{\ \ \ elm\_object\_text\_set(bt,\ \textcolor{stringliteral}{"{}\#"{}});}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Box__Group_ga66a10dd861578521af2ab7b8c2ca65c5}{elm\_box\_pack\_end}}(box,\ bt);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga07208fcafd4739de606bc35fff684bf5}{evas\_object\_show}}(bt);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Smart__Object__Group_gac12dd6655f488cc47ce6cf00eb7d12b2}{evas\_object\_smart\_callback\_add}}(bt,\ \textcolor{stringliteral}{"{}clicked"{}},\ \_bt\_zoom\_fill,\ map);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_gaaf1d3e26e36b316977336066b6f56632}{evas\_object\_size\_hint\_align\_set}}(bt,\ \mbox{\hyperlink{Evas__Common_8h_aecbac710f36d52911fc34dcdaf8e729c}{EVAS\_HINT\_FILL}},\ 0);}

\end{DoxyCodeInclude}
 Next we set the box to be vertical and change it\textquotesingle{}s size, weight and alignment, so it will occupy the top of the window, from left to right\+: 
\begin{DoxyCodeInclude}{0}

\end{DoxyCodeInclude}
 We\textquotesingle{}ll add an entry with a preliminary address, that I know will find a coordinate, to exemplify how names work. But you can try lots of addresses. From city or country names to pubs, or whatever you want. To try is enough to run the example, type the address and press \char`\"{}\+Route\char`\"{} button. This button will call a function that will get the typed address and find the route. 
\begin{DoxyCodeInclude}{0}

\end{DoxyCodeInclude}
 The button pass an structure instance we make for this example, with all the fields we\textquotesingle{}ll need.  
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{keyword}{typedef}\ \textcolor{keyword}{struct\ }\_Example\_Data}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}}\ *map,\ *entry;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{struct__Elm__Map__Route}{Elm\_Map\_Route}}\ *route;}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{double}\ start\_lon,\ start\_lat,\ dest\_lon,\ dest\_lat;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{struct__Elm__Map__Name}{Elm\_Map\_Name}}\ *name;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{struct__Elm__Map__Overlay}{Elm\_Map\_Overlay}}\ *route\_ovl;}
\DoxyCodeLine{\}\ Example\_Data;}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ Example\_Data\ example\_data;}

\end{DoxyCodeInclude}
 Let\textquotesingle{}s initialize it\textquotesingle{}s fields\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ example\_data.map\ =\ map;}
\DoxyCodeLine{\ \ \ example\_data.entry\ =\ entry;}
\DoxyCodeLine{\ \ \ example\_data.route\ =\ NULL;}
\DoxyCodeLine{\ \ \ example\_data.start\_lon\ =\ -\/43.175;}
\DoxyCodeLine{\ \ \ example\_data.start\_lat\ =\ -\/22.97;}

\end{DoxyCodeInclude}
 {\ttfamily map} and {\ttfamily entry} are our elementary objects, {\ttfamily route} is set to {\ttfamily NULL}, since we don\textquotesingle{}t have one yet, and the coordinates of the start point is set (longitude and latitude).

Also, let\textquotesingle{}s show this start point at the center of the map, and set a zoom nice enough to close it\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Map__Group_gac18d4869797cf49e4fa2e50a3de592f3}{elm\_map\_region\_show}}(map,\ example\_data.start\_lon,\ example\_data.start\_lat);}

\end{DoxyCodeInclude}
 These lines were already explained on \mbox{\hyperlink{map_example_02}{Map Example 2}}.

Now we\textquotesingle{}ll see the \char`\"{}\+Route\char`\"{} button callback function\+:  
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{\_name\_loaded(\textcolor{keywordtype}{void}\ *data,\ \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}}\ *obj,\ \textcolor{keywordtype}{void}\ *ev\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ Example\_Data\ *exam\_data\ =\ data;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}}\ *map\ =\ obj;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (exam\_data-\/>route)}
\DoxyCodeLine{\ \ \ \ \ \mbox{\hyperlink{group__Elm__Map__Group_gaf3eeb8329e577c8b7c08c9ddc656df77}{elm\_map\_route\_del}}(exam\_data-\/>route);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Map__Group_gae5c6d7cfa664af6387d73637953b196e}{elm\_map\_name\_region\_get}}(exam\_data-\/>name,\ \&(exam\_data-\/>dest\_lon),}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \&(exam\_data-\/>dest\_lat));}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ exam\_data-\/>route\ =\ \mbox{\hyperlink{group__Elm__Map__Group_ga38d35b042b9cd38662b231d7dc74f011}{elm\_map\_route\_add}}(map,\ \mbox{\hyperlink{group__Elm__Map__Group_gga475f32243c8d8fcb3081b80194f8fe27a6433a84142f9bb8eb914ae9f482cdb95}{ELM\_MAP\_ROUTE\_TYPE\_FOOT}},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Elm__Map__Group_ggaaa4a6dd08f05a645f2c963c05e1c1186ab0b4e63fbeac790d7e1769695b17910b}{ELM\_MAP\_ROUTE\_METHOD\_SHORTEST}},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ exam\_data-\/>start\_lon,\ exam\_data-\/>start\_lat,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ exam\_data-\/>dest\_lon,\ exam\_data-\/>dest\_lat,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ NULL,\ NULL);}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 First we get the address string from our entry. Then we use {\ttfamily name} conversion util functions, so we could get coordinates for this address. These functions return an \mbox{\hyperlink{group__Elm__Map__Group_ga73173d5c600925adcbaac5c55f5462d3}{Elm\+\_\+\+Map\+\_\+\+Name}} handle for us. Function elm\+\_\+map\+\_\+name\+\_\+geo\+\_\+request() will do this job for us, but it\textquotesingle{}s an asynchronous function, since it requires this information from the server.

That\textquotesingle{}s the reason we need to wait for {\ttfamily  \char`\"{}name,loaded\char`\"{} } signal. We add a callback function for this\+:  
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{\_route\_loaded(\textcolor{keywordtype}{void}\ *data,\ \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}}\ *obj,\ \textcolor{keywordtype}{void}\ *ev\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ Example\_Data\ *exam\_data\ =\ data;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ exam\_data-\/>route\_ovl\ =\ \mbox{\hyperlink{group__Elm__Map__Group_ga719f190d9152d25967ff63f356bf77d0}{elm\_map\_overlay\_route\_add}}(obj,\ exam\_data-\/>route);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Map__Group_ga2ef4c31306107b391f13e965813f60cd}{elm\_map\_overlay\_color\_set}}(exam\_data-\/>route\_ovl,\ 0,\ 255,\ 0,\ 255);}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 This function will check if a previous route was traced, and if it was, it will remove it. Next we\textquotesingle{}ll get destination coordinates from our {\ttfamily name}, and use them to add a new route.

To trace a route we need to know how the user will go through the path. Let\textquotesingle{}s suppose he\textquotesingle{}ll be walking, but doesn\textquotesingle{}t like to walk, so we need to choose the shortest path instead of the route that would made him spend less time. Coordinates of the point from where he will start and of the destination point need to be passed as well.

Finally we\textquotesingle{}ll set a color different from solid red (default), to show our route. We set it green.

See \mbox{\hyperlink{map_example_03_8c-example}{map\+\_\+example\+\_\+03.c}} for full source, whose window should look like this picture\+:

 
\begin{DoxyImageNoCaption}
  \mbox{\includegraphics[width=\textwidth]{screenshots/map_example_03}}
\end{DoxyImageNoCaption}
 