google-maps - Xamarin.Forms:无需 API 调用即可更快地显示最近位置?
问题描述
我有一个简单的Xamarin.Forms
应用程序,它根据我当前的位置显示最近的沃尔玛商店列表。
假设我的 SQL 数据库有 200 多行;每行都有我所在德克萨斯州的沃尔玛商店的坐标。
所以我最初的逻辑是检索我的位置与所有 200 多个沃尔玛位置之间的距离,如下所示:
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
}
然后,一旦walmartList
有了我的位置与所有 200 多家沃尔玛之间的距离,我将在我ListView
的位置中显示距离小于 10 英里的位置。
所以,我的问题是:如何限制对 Google 地图的 API 调用量?现在,我需要查询 Google 地图 200 多次,然后显示指定距离(即 10 英里)内的商店。
如果我目前在德克萨斯州休斯顿的位置是12 Oaks Dr,那么我为什么需要获取德克萨斯州所有商店的位置?但我不知道如何在不调用 Google Maps API 并获取实际距离的情况下限制搜索。
解决方案
推荐阅读
- ruby-on-rails - 如何在 rails 6 或 rails 7 alpha 引擎中使用 jqueryUI
- c++ - 使用 GDB 将字符串传递给函数
- c++ - 我们如何知道一个指针是用 new 还是 new[] 分配的?
- sql - 了解 SQL Server 执行计划
- html - CSS 悬停属性不适用于嵌套 div
- javascript - 如何测试从 REST api 获取它的 src 属性的反应图像组件
- amazon-web-services - AWS lambda 部署问题 - 权限不足
- generics - 同一个列表中非常相似的类型(继承 vs 区分联合 vs 泛型?)
- django - 对 on_delete.SET() 使用参数或类方法?(如何在删除时更改 ForeignKey 字段)
- ruby-on-rails - 无法使用 Select2 在轨道上创建标签