android:如何转换gps坐标并使用post方法将其发送到mysql服务器

时间:2013-02-14 10:24:04

标签: http-post

我正在尝试在我的php服务器中发送数据,但数据是纬度和经度格式。

这是错误:Error parsing data org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject

private class sendlocation extends AsyncTask<String,String,String>

{

@Override
protected String doInBackground(String... args0) 
{       
    double latlat = gps.getLatitude();
    double longlong = gps.getLongitude();
    String resultlat = Double.toString(latlat);
    String resultlong = Double.toString(longlong);

    List<NameValuePair> params = new ArrayList<NameValuePair>(2);
    params.add(new BasicNameValuePair("Latitude",resultlat));
    params.add(new BasicNameValuePair("Longitude",resultlong));
    JSONObject json = jsonParser.makeHttpRequest(url_send_loc,"POST", params);

    Log.d("Create Response", json.toString());
    try
    {
        int success = json.getInt(TAG_SUCCESS);
        if(success == 1)
        {
            Toast.makeText(getApplicationContext(),"Location Successfully sent: \nLat "+resultlat+" nLong" + resultlong ,Toast.LENGTH_LONG).show();

        }
        else
        {   pdialog.dismiss();
            Toast.makeText(getApplicationContext(), "Unknown error! Location not sent", Toast.LENGTH_LONG).show();
        }
    }catch(JSONException e)
    {
        e.printStackTrace();
    }
    return null;
};
}

0 个答案:

没有答案