This code places an Elementary map widget on a window, to exemplify part of the widget's API.
Let's start adding a map to our window:
It's enough to display a world map inside our window. But usually you'll need to let user interact with the map. We need to place some buttons, so the user could control the map. It's done on the following code. If you don't know about boxes, or buttons, check their examples, Box Example 1 and Button Example 1.
We are adding callback functions that will be called when the user clicks over these buttons. Let's study such functions, starting from the function that will zoom in the map:
First thing done is assure zoom mode is set to manual. It's the default mode, but the other buttons will change this, so before setting a new zoom value, we need to change the zoom mode.
Then, we get the current zoom value, increment that, and set the new value to the map. If it's bigger than max zoom value allowed, it will remain on the maximum allowed, nothing bad will happen. This way we don't need to check first if it won't be bigger than max.
Zoom out function is basically the same thing, but zoom will be decremented instead of incremented:
The "X" button, when pressed, will call a function that will zoom the map until it fits inside the scroll frame with no pixels outside this area:
And the "#" button, will call a function that will zoom until map fills scroll, ensuring no pixels are left unfilled:
But we can also set map to show something different from default world map, changing the zoom level and region shown. Let's pick a wonderful city coordinates, one placed at
43 20 S, 22 90 W . Since map uses double variables to represent latitude and longitude, to represent north or east, we should represent it as positive values, and south or west as negative. Also, the value will be represented as degree.min. So, for example, our longitude
43 20 S will be represented by the value
-43.20 . A zoom set to
12 should be enough to show a city.
See map_example_01.c for full source, whose window should look like this picture: