I am writing a program about drawing a route of a person with using initial GPS values of that person.
To do that I have implemented all locationListener code and I put all coordinate values into a vector. But the problem that I have now is that, I want to put them into mySQL and I dont know how to send a vector to Php file. Can you please help me with that ?
Note : I do not want to send values via URL so thats why I want to send the whole vector.
package project;
import java.util.Vector;
import javax.microedition.location.Location;
import javax.microedition.location.LocationException;
import javax.microedition.location.LocationListener;
import javax.microedition.location.LocationProvider;
import net.rim.device.api.gps.BlackBerryCriteria;
import net.rim.device.api.gps.BlackBerryLocationProvider;
import net.rim.device.api.gps.GPSInfo;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.container.MainScreen;
public class RoutePaint extends MainScreen implements LocationListener,
FieldChangeListener {
public double latitude;
public double altitude;
public double longitude;
public float velocity;
public Vector locations;
private BlackBerryCriteria myCriteria;
private BlackBerryLocationProvider myProvider;
private Point point;
private ButtonField locVector;
public RoutePaint() {
locations = new Vector();
locVector = new ButtonField("Locations Vector",
ButtonField.CONSUME_CLICK);
locVector.setChangeListener(this);
add(locVector);
myCriteria = new BlackBerryCriteria(GPSInfo.GPS_MODE_AUTONOMOUS);
try {
myProvider = (BlackBerryLocationProvider) LocationProvider
.getInstance(myCriteria);
} catch (LocationException e) {
e.printStackTrace();
}
myProvider.setLocationListener(this, 3, -1, -1);
}
public void locationUpdated(LocationProvider provider, Location location) {
// TODO Auto-generated method stub
point = new Point();
latitude = location.getQualifiedCoordinates().getLatitude();
altitude = location.getQualifiedCoordinates().getAltitude();
longitude = location.getQualifiedCoordinates().getLongitude();
velocity = location.getSpeed();
point.x = latitude;
point.y = longitude;
locations.addElement(point);
invalidate();
}
public void providerStateChanged(LocationProvider arg0, int arg1) {
// TODO Auto-generated method stub
}
public boolean onClose() {
Dialog.inform("Exiting project!");
System.exit(0);
return true;
}
public void fieldChanged(Field field, int context) {
if (field == locVector) {
getUiEngine().pushScreen(new LocationsVector(locations));
}
}
}
OK, the overall game plan is:
"Content-Type"header should be"application/x-www-form-urlencoded").A sample post data in your case could look as the following:
Here for a Point you have a pair of params (
point_N_xandpoint_N_y, whereNis index in yourVector). However the exact format is up to you. The only reason to know the format is to be able to write a parser on web part. I am sure you are able to generate smth similar (most likely more compact) by iterating through theVector.Googling you can find some examples on how to send a POST request on BB. For instance, look here and here as a starting point. Also make sure you have studied the official API (scroll to “Example using POST with HttpConnection”).