DJ-DOO 0 Newbie Poster

Hi folks,

I'm newish to android, very inexperienced. I'm trying to develop an application that transmits the coordinates of one phone (client a) to (client b) via a java server, I then want to check the distance between clients. I have managed to get the coordinates of client a, send them via a socket to the server and then onto client b. The problem is I send them in a string format. In order to make use to make use of the distanceTo() method in the android.loaction I need to have a double lat and double long of client a.

I'm just attaching a snippet of code from client a how I'm sending the coordinates.

public void onLocationChanged(Location location) {
            // TODO Auto-generated method stub
             latitude = location.getLatitude();
             longitude = location.getLongitude();

             coordinates = (""+latitude + longitude);


The transmit method is a follows

private void Transmit(final String message) {

    Thread trans = new Thread(new Runnable() {

        public void run() {

            Log.d("TRANSMIT", "CALLED");

            // TODO Auto-generated method stub
            try {

                s = new Socket("", 2222); // connect to
                                                        // server
                Log.d("CONNECTED", "Connected");

                DataOutputStream _OutPut = new DataOutputStream(
                _OutPut.writeBytes(message + "\n");

            } catch (UnknownHostException e) {
            } catch (IOException e) {

So client b recieves the coordinates as a string and I'm unsure as to how to use the coorinates in string format in the distanceTo() method or how to extract them out of a string, or should i send them in a double array? So I need to take them out as individual doubles i.e. client a lat = client a long =.

Any help on this would be appreciated, as I'm starting to find my feet but there are certain things that throw up problems.

Thanks in advance.


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.