我希望在我的应用程序中循环发送经纬度。以下是使用GPS获取这些参数的功能。
private void showLocation(Location location) {
String latitude = "Latitude: ";
String longitude = "Longitude: ";
if (location != null) {
latitude += location.getLatitude();
longitude += location.getLongitude();
}
}
我在网上寻找方法,找到了一些但它们已经过时且无法使用。
public void sendData(double latitude, double longitude){
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.x.x.x:8080/run/mypage.php");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("Latitude", Double.toString(latitude)));
nameValuePairs.add(new BasicNameValuePair("Longitude", Double.toString(longitude)));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}