Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从当前位置查找最近的餐厅?_C#_Android_Sql Server_Xamarin - Fatal编程技术网

C# 从当前位置查找最近的餐厅?

C# 从当前位置查找最近的餐厅?,c#,android,sql-server,xamarin,C#,Android,Sql Server,Xamarin,我有sql server 2012数据库。我有一位餐馆老板。在那张表中,我存储了餐厅的纬度和经度。现在我想做的是,当用户搜索餐厅时,他可以使用距离进行排序。所以我得到了用户的当前位置(lat,long),但与sql查询混淆了如何执行计算 这是我的桌子 RestLatitude RestLongitude Restid 21.1784472 72.9627693 1 21.5724180 72.9648222 2 根据当前用

我有sql server 2012数据库。我有一位餐馆老板。在那张表中,我存储了餐厅的纬度和经度。现在我想做的是,当用户搜索餐厅时,他可以使用距离进行排序。所以我得到了用户的当前位置(lat,long),但与sql查询混淆了如何执行计算

这是我的桌子

RestLatitude    RestLongitude    Restid
21.1784472        72.9627693        1
21.5724180        72.9648222        2  

根据当前用户位置,我的预期输出希望首先显示最近的餐厅。

有一个简单的方法

首先将纬度和经度转换为数字

那就试试类似的东西

select resturent,cast(restLatitude as numeric(18,10))-cast(@userLatitude as numeric(18,10)) as Distance from table order by Distance asc
再加上经度

所以从逻辑上讲,最小的值将是最近的位置


p.S尝试类似的方法这不是准确的方法,但你可以这样做

用户搜索会包括radius吗?或者距离用户位置的距离?您是否从谷歌的direction api获取餐厅lat/lng值???@icaneatclouds无半径无距离。!首先是最近的一个,最后是最远的一个,不管最近的一个在100英里之外。@sumit no我正在使用GoogleLocationService(dll C#Code)选择cast(restaurantlatude作为数字(18,10))-cast(@userlat作为数字(18,10))-cast(restaurantlongite作为数字(18,10))-cast(@uselong作为数字(18,10))从表顺序到表顺序的距离是这样的吗?是的,类似于hat,但您不需要减去所有值选择cast(restaurantlatude作为数字(18,10))-cast(@userlat作为数字(18,10))作为纬度,cast(restaurantlongite作为数字(18,10))-cast(@uselong作为数字(18,10))作为从表顺序到距离asc的数字