0

我目前有一个 Web 服务,我在 Visual Basic 中构建为 Visual Studio 2010 中的 asmx Web 服务。目前,当我使用我的 android 应用程序查询 Web 服务时,我从数据库中获得指定数量的地址。我需要的是 Android 应用程序将用户当前位置传递给网络服务,并让它返回数据库中最近的 10 个地址的列表,但我该怎么做呢?

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

<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()
4

1 回答 1

1

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

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

掌握所有纬度/经度值后,您需要在查询中使用 sin/cos 公式从数据库中返回前 5 或前 10 条记录。

干杯

于 2013-04-24T02:07:20.823 回答