Installation guide
35
Appendix-1
// MyLocationListner
class MyLocationListener implements LocationListener
{
public void onLocationChanged(Location loc)
{
// TODO Auto-generated method stub
Lon = loc.getLongitude();
Lat = loc.getLatitude();
point = new GeoPoint((int)(Lat*1e6), (int)(Lon*1e6));
mapView.getOverlays().add(myOverlay);
mapController.animateTo(point);
//send updated latitude and longitude to the server
try
{
url = new URL(strUrl);
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
urlConn.setRequestMethod("POST");
urlConn.setUseCaches(false);
urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
urlConn.setRequestProperty("Charest", "utf-8");
// to connect to the server side
urlConn.connect();
DataOutputStream dop = new DataOutputStream(urlConn.getOutputStream());
dop.writeBytes("point=" + URLEncoder.encode("location","utf-8"));
//it is essential that to add "&" to separate two strings
dop.writeBytes("&username=" + URLEncoder.encode(username,"utf-8"));
dop.writeBytes("&password=" + URLEncoder.encode(password,"utf-8"));
dop.writeBytes("&lon=" + URLEncoder.encode(Double.toString(Lon),"utf-8"));
dop.writeBytes("&lat=" + URLEncoder.encode(Double.toString(Lat),"utf-8"));
dop.flush();
dop.close();
DataInputStream dis = new DataInputStream(urlConn.getInputStream());
String locPassage = dis.readUTF();
// to disconnect the server side
urlConn.disconnect();
if("Succeed".equalsIgnoreCase(locPassage))
{
//nothing
}
}
catch (MalformedURLException e)