The example of program
Now let's write a small application that will determine the Naviaddress nearest to your location.
For this purpose, let's determine a sequence of actions:
- First of all, we get the current coordinates of the notebook or phone which the program will be executed on using the Geolocation API, embedded in any modern browser. The system should ask the user for access permission to this useful information.
- Around the received coordinates create a small square of four points spaced away from the initial point at a distance of one thousandth of a degree (we will write this value in advance to the DELTA constant).
- Get the list of all Naviaddresses inside this square. Limit the number of provided Naviaddresses using the LIMIT constant.
- Using the calculation of the Euclidean distance for each point we find the nearest Naviaddress to our location.
- And, finally, get data of the nearest Naviaddress.
operator and wrap them into the asynchronous main()
function. Actually, nothing prevents us from doing the same with traditional callback-calls.