Hi, I am building a simple android application that sends GPS coordinates from an Android phone to a Webserver, and the received co-ordinates are displayed one by one in the server. I think both my client and server side programs are correct, but I am not sure. Please correct the code if its not correct.
Where/How can I see the received co-ordinates?
Also I need to see it like this
Latitude Longitude
55.17 -3.48
52.18 -2.11
50.23 -1.45
the 1st 55.17 and -3.48 are displayed when the server receives it and both 55.17,-3.48 and 52.18,-2.11 are displayed when the second coordinates are received.
Here is the Android(client)code: UseGps.java
package Firstdroid.Gps;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Toast;
public class UseGps extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/* Using the LocationManager class to obtain GPS locations */
LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
}
/* Class My Location Listener */
public class MyLocationListener implements LocationListener
{
public void onLocationChanged(Location loc)
{
loc.getLatitude();
loc.getLongitude();
String Text = "My current location is: " + "Latitude = " + loc.getLatitude() + "Longitude = " + loc.getLongitude();
Toast.makeText( getApplicationContext(), Text, Toast.LENGTH_LONG).show();
String url = "http://localhost:80/xampp/server.php?lat="+loc.getLatitude()+"&long="+loc.getLongitude();
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
HttpResponse response = httpclient.execute(httppost);
System.out.println(EntityUtils.toString(response.getEntity()));
} catch (Exception e){
e.printStackTrace();
}
}
public void onProviderDisabled(String provider)
{
Toast.makeText( getApplicationContext(), "Gps Disabled", Toast.LENGTH_LONG ).show();
}
public void onProviderEnabled(String provider)
{
Toast.makeText( getApplicationContext(), "Gps Enabled", Toast.LENGTH_LONG ).show();
}
public void onStatusChanged(String provider, int status, Bundle extras)
{
}
}/* End of Class MyLocationListener */
}/* End of UseGps Activity */
Serverside Program:
<html>
<head>
<title>GPS TEST</title>
</head>
<body>
<?php echo '<p>Latitude Longitude</p>';
echo $_GET['lat'];echo $_GET['long'];
?>
</body>
</html>