C#中的GeoCoordinate

时间:2013-12-12 17:39:51

标签: c# location

f_lat应返回客户纬度值,但某处出现错误,因此返回1(返回1不是预期的结果)。

客户和驱动程序的坐标从数据库中正确返回。

当我在return f_lat;构造函数之前放置GeoCoordinate时,它会返回正确的客户纬度,但是在GeoCoordinate构造函数之后,它会返回错误的客户纬度。

谁可以帮助我?

[WebMethod]
public double FindNearestTaxiDriver(string f_mobilephone)
{


    double f_lat = 0.0;
    double f_lng = 0.0;

    ArrayList d_mobilephone = new ArrayList();
    ArrayList d_lat = new ArrayList();
    ArrayList d_lng = new ArrayList();

    ArrayList distanceBetweenTwoPoints = new ArrayList();

    MySqlConnection mySqlConnection = new MySqlConnection(ConfigurationManager.ConnectionStrings["connect"].ToString());
    MySqlCommand f_mySqlCommand = new MySqlCommand("Select f_lat,f_lng from farecoordinates where f_mobilephone='" + f_mobilephone + "'",mySqlConnection);
    MySqlCommand d_mySqlCommand = new MySqlCommand("Select d_mobilephone,d_lat,d_lng from drivercoordinates", mySqlConnection);

    try
    {
        mySqlConnection.Open();
        MySqlDataReader mySqlDataReader = f_mySqlCommand.ExecuteReader();
        while (mySqlDataReader.Read())
        {
            f_lat = Convert.ToDouble(mySqlDataReader["f_lat"].ToString());
            f_lng = Convert.ToDouble(mySqlDataReader["f_lng"].ToString());
        }

        mySqlDataReader.Dispose();

        mySqlDataReader = d_mySqlCommand.ExecuteReader();

        while (mySqlDataReader.Read())
        {
            d_mobilephone.Add(mySqlDataReader["d_mobilephone"].ToString());
            d_lat.Add(Convert.ToDouble(mySqlDataReader["d_lat"].ToString()));
            d_lng.Add(Convert.ToDouble(mySqlDataReader["d_lng"].ToString()));
        }
        GeoCoordinate f_coordinates = new GeoCoordinate(f_lat, f_lng);
        GeoCoordinate d_coordinates = new GeoCoordinate();

        for (int i = 0; i < d_mobilephone.Count; i++)
        {
            d_coordinates.Latitude = Convert.ToDouble(d_lat[i]);
            d_coordinates.Longitude = Convert.ToDouble(d_lng[i]);

            distanceBetweenTwoPoints.Add(f_coordinates.GetDistanceTo(d_coordinates));
        }
        //distanceBetweenTwoPoints.Sort();
        return f_lat;

    }
    catch (Exception)
    {

        return 1.0;
    }
    finally
    {
        f_mySqlCommand.Dispose();
        mySqlConnection.Dispose();
        mySqlConnection.Close();
    }
}

0 个答案:

没有答案