A simple user nearest atm search algorithm in Golang
- Golang (compiled language)
-
helpers.go a. Contains a function
distance
necessary to calculate distance between two latitudes and longitudes b. Containes sorting functions based on thegolang
sorting library -
main.go a. Contains detailed algorithm function and the main function to execute the code
- Each Atm is represented as struct with type of
id, latitude and longitude
- A user is represented as a struct with type of
id, latitude and longitude
- A user at a certain
location (l)
is far away distance (x) from the nearest atm - A user scans the current
location(l)
and gets results of the closest atm which is a shortdistance (x)
away from the current userlocation (l)
- Get the user location
- Find the shortest distance atm from the user
- Give the user results about the closest atm
-
Get the user location a. Scan the users gps to get the current latitude and longitude b. if not present abort with an error and exit c. if present scan the database with atms whose latitude and longitude are 2 times less the latitude and longitude of the current user (to filter out some very far away atms)
-
Finding the shortest distance atm a. Sort the filter atm list starting with the one with the smallest calculated distance value in kilometers b. Return the atm with min value of distance from the current user
-
Results a. Return the user with the details of the closest atm
- Install the Golang sdk or use the go playground online
- Clone the repository
- Through the command line
cd src
into src directory of the folder "Coseke_atm_search_algorithm" - Then execute the command
go run main.go
to see test results