首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我有一个asp.net .asmx the服务,需要返回最接近查询the服务的客户端的地址列表

我有一个asp.net .asmx the服务,需要返回最接近查询the服务的客户端的地址列表
EN

Stack Overflow用户
提问于 2013-04-24 08:02:42
回答 1查看 183关注 0票数 0

我目前有一个webservice,它是我在visual Studio2010中用Visual basic构建的asmx webservice。目前,当我用我的android应用程序查询get服务时,我从数据库中获得了指定数量的地址。我需要的是Android应用程序将用户的当前位置传递给but服务,并让它返回数据库中最近的10个地址列表,但我该如何做到这一点呢?

下面是我查询数据库的方法。

代码语言:javascript
复制
<WebMethod()> _
Public Function GetFuelStops(ByVal skip As Integer, ByVal take As Integer) As FuelStop()
    Dim resultList = New List(Of FuelStop)()

    Using sqlCon As New SqlConnection()
        sqlCon.ConnectionString = "Data Source=(local);Initial Catalog=****;User ID=****;Password=***(***"
        Dim sql = <sql>
            SELECT
                [Physical_Address_Street]
                , [Physical_Address_Local]
                , [Physical_Address_State]
                , [Physical_Address_Zip]
                , [Phone_Number]
            FROM Gas_Stations
            WHERE Location_Type = 1
            </sql>

        Dim command As New SqlCommand()
        command.CommandText = CStr(sql)
        command.Connection = sqlCon
        sqlCon.Open()

        Using reader = command.ExecuteReader()
            While reader.Read()
                Dim fuelStop = New FuelStop()
                fuelStop.Physical_Address_Street = reader.GetString(0)
                fuelStop.Physical_Address_Local = reader.GetString(1)
                fuelStop.Physical_Address_State = reader.GetString(2)
                fuelStop.Physical_Address_Zip = reader.GetString(3)
                fuelStop.Phone_Number = reader.GetString(4)

                resultList.Add(fuelStop)
            End While
        End Using
    End Using
    Return resultList.Skip(skip).Take(take).ToArray()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-24 10:07:21

您的应用程序需要启用GPS (这将触发当前位置坐标),即纬度和经度。

同时,您的数据库表应该具有每个地址的纬度和经度值,因为这些纬度和经度值将用于距离比较。

一旦有了所有的纬度/经度值,就需要在查询中使用sin/cos公式从数据库中返回前5条或前10条记录。

干杯

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16181158

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档