This code places an Elementary map widget on a window, to exemplify part of the widget'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'll trace a route on the map.
We'll start this example in the same way Map Example 1. Adding a map with buttons to control zoom, so if you didn't read it yet, just do it now. Actually there is a change, that we're aligning buttons to the top, since we wan't a vertical control box this time.
Next we set the box to be vertical and change it's size, weight and alignment, so it will occupy the top of the window, from left to right:
We'll add an entry with a preliminar address, that I know will find a coordinate, to examplify 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 "Route" button. This button will call a function that will get the typed address and find the route.
The button pass an structure instance we make for this example, with all the fields we'll need.
Let's initialize it's fields:
entry are our elementary objects,
route is set to
NULL, since we don't have one yet, and the coordinates of the start point is set (longitude and latitude).
Also, let's show this start point at the center of the map, and set a zoom nice enough to close it:
These lines were already explained on Map Example 2.
Now we'll see the "Route" button callback function:
First we get the address string from our entry. Then we use
name conversion util functions, so we could get coordinates for this address. These functions return an Elm_Map_Name handle for us. Function elm_map_name_geo_request() will do this job for us, but it's an asynchronous function, since it requires this information from the server.
That's the reason we need to wait for
"name,loaded" signal. We add a callback function for this:
This function will check if a previous route was traced, and if it was, it will remove it. Next we'll get destination coordinates from our
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's suppose he'll be walking, but doesn'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'll set a color different from solid red (default), to show our route. We set it green.
See map_example_03.c for full source, whose window should look like this picture: