Currently, I am developing an application that involves numerous locations with coordinates. One of the key features I want to implement is the ability to search for locations by their names or find the closest one based on user input. To achieve this, I plan to calculate the distance between two sets of coordinates using the haversine formula. My approach involves iterating through an array of location objects and adding a new element called distance
, representing the distance from my current location to each respective location. However, the code I have written doesn't seem to work as intended. Any suggestions or ideas?
function GetLocation(location) {
// Code snippet here
}
Below are examples of some locations within the application:
"name": "502 Nelson St, Greenville, MS 38701",
// Location details here
}, {
"name": "242 Blackhawk Trace, Galena, IL 61036",
// Location details here
}, {
"name": "3747 Ocean Dr, Vero Beach, FL 32963",
// Location details here
}
If you prefer, you can view the demonstration of my app's functionality through the following link:
http://plnkr.co/edit/nRQc7Ym0lsaK6jQwd626?p=preview