This code places an Elementary map widget on a window, to exemplify part of the widget\textquotesingle{}s A\+PI, 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_ga509621f20872fe3ef3418919f7fda396}{elm\_map\_add}}(win);}
\DoxyCodeLine{   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_ga505d6bd217e5ee01e82b548ec35986eb}{elm\_win\_resize\_object\_add}}(win, map);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}}(map);}
\DoxyCodeLine{}
\DoxyCodeLine{   box = \mbox{\hyperlink{group__Elm__Box_ga3d0998b60ada633bacfa8869a921cfd7}{elm\_box\_add}}(win);}
\DoxyCodeLine{   elm\_box\_horizontal\_set(box, \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}});}
\DoxyCodeLine{   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_ga505d6bd217e5ee01e82b548ec35986eb}{elm\_win\_resize\_object\_add}}(win, box);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}}(box);}
\DoxyCodeLine{}
\DoxyCodeLine{   bt = \mbox{\hyperlink{group__Elm__Button_ga0021b9d86d822367035843ed18bc6ea9}{elm\_button\_add}}(win);}
\DoxyCodeLine{   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"+"});}
\DoxyCodeLine{   elm\_box\_pack\_end(box, bt);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}}(bt);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Smart__Object__Group_ga18a8b179f94d21b2b09e19db11741061}{evas\_object\_smart\_callback\_add}}(bt, \textcolor{stringliteral}{"clicked"}, \_bt\_zoom\_in, map);}
\DoxyCodeLine{   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_ga0021b9d86d822367035843ed18bc6ea9}{elm\_button\_add}}(win);}
\DoxyCodeLine{   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"-\/"});}
\DoxyCodeLine{   elm\_box\_pack\_end(box, bt);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}}(bt);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Smart__Object__Group_ga18a8b179f94d21b2b09e19db11741061}{evas\_object\_smart\_callback\_add}}(bt, \textcolor{stringliteral}{"clicked"}, \_bt\_zoom\_out, map);}
\DoxyCodeLine{   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_ga0021b9d86d822367035843ed18bc6ea9}{elm\_button\_add}}(win);}
\DoxyCodeLine{   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"X"});}
\DoxyCodeLine{   elm\_box\_pack\_end(box, bt);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}}(bt);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Smart__Object__Group_ga18a8b179f94d21b2b09e19db11741061}{evas\_object\_smart\_callback\_add}}(bt, \textcolor{stringliteral}{"clicked"}, \_bt\_zoom\_fit, map);}
\DoxyCodeLine{   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_ga0021b9d86d822367035843ed18bc6ea9}{elm\_button\_add}}(win);}
\DoxyCodeLine{   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"\#"});}
\DoxyCodeLine{   elm\_box\_pack\_end(box, bt);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}}(bt);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Smart__Object__Group_ga18a8b179f94d21b2b09e19db11741061}{evas\_object\_smart\_callback\_add}}(bt, \textcolor{stringliteral}{"clicked"}, \_bt\_zoom\_fill, map);}
\DoxyCodeLine{   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 N\+U\+LL}, 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{   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_gaf3eeb8329e577c8b7c08c9ddc656df77}{elm\_map\_route\_del}}(exam\_data-\/>route);}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__Map_gae5c6d7cfa664af6387d73637953b196e}{elm\_map\_name\_region\_get}}(exam\_data-\/>name, \&(exam\_data-\/>dest\_lon),}
\DoxyCodeLine{                           \&(exam\_data-\/>dest\_lat));}
\DoxyCodeLine{}
\DoxyCodeLine{   exam\_data-\/>route = elm\_map\_route\_add(map, \mbox{\hyperlink{group__Elm__Map_gga475f32243c8d8fcb3081b80194f8fe27a6433a84142f9bb8eb914ae9f482cdb95}{ELM\_MAP\_ROUTE\_TYPE\_FOOT}},}
\DoxyCodeLine{                                        \mbox{\hyperlink{group__Elm__Map_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_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 = elm\_map\_overlay\_route\_add(obj, exam\_data-\/>route);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__Map_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}
 