I have a simple Xamarin.Forms
app that displays a list of the closest Walmart stores based on my current location.
Let's say my SQL database has 200+ rows; each row has the coordinates of a Walmart store in my state of Texax.
So my initial logic was to retrieve the distance between my location and all 200+ Walmart locations, something like this:
Datatable walmartTable = GetAllWalmarts();
string distanceUrl = "https://maps.google.com/maps/api/distancematrix/xml?origins=MyLocationX,MyLocationY&destinations={2},{3}&mode=driving";
List<Walmarts> walmartList=new List<Walmarts>();
foreach(DataRow row in walmartTable.Rows)
{
x_walmart = row["x];
y_walmart = row["y];
currentWalmartName = row["name"];
// Build distanceUrl variable with x_walmart & y_walmart
// Call distanceUrl API that returns "distance in miles"
// Add "distance in miles" to an array, something like this: list.add(currentWalmartName, x_walmart, y_walmart, "distance in miles");
// Go to the next Walmart store
}
Then, once walmartList
has the distance between my location and all 200+ walmarts, I will display in my ListView
the locations with a distance of less than 10 miles.
So, my question is: how can I limit the amount of API calls to Google Maps? Right now, I would need to query Google Maps 200+ times and then display the stores that fall within the distance specified (ie. 10 miles).
If my current location in Houston, Texas is 12 Oaks Dr, then why would I need to get the locations of all stores in Texas? But I don't know how to limit that search without calling the Google Maps API and getting the actual distance.