Sending Android GPS coordinates via streams
I want to send GPS coords from my phone to a remote server running Java. I' ve managed to send data with streams 开发者_Go百科but i don' t really know how to send the coords. I used DataStreams to send integers before. What data type are the coordinates? Should i use ObjectStreams or what?
you can also create a serializable object with gps coordinates as attributes and send it over a objectoutputstream but this means that you need a java VM on the other side
No ObjectStreams. Use DataInputStream and DataOutputStream wrappers for your input- and outputstreams and make something like
-(void)write(DataoutputStream dout) {
dout.writeInt(type);
dout.writeDouble(lat);
dout.writeDouble(lon);
dout.writeDouble(alt);
}
-(void)read(DatainputStream din) {
type = din.readInt();
lat = din.readDouble();
lon = din.readDouble();
alt = din.readDouble();
}
which is the start of making some kind of protocol if you want. Of course, if you have an option to send using HTTP, go for XML or some kind of JSON format, i.e.
<GeographicPosition longitue="1.2" latitide="-0.3" altitude="133" />
or something like that.
精彩评论