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);

             Transmit(coordinates);         
        }   

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("192.168.1.1", 2222); // connect to
                                                        // server
                Log.d("CONNECTED", "Connected");

                DataOutputStream _OutPut = new DataOutputStream(
                        s.getOutputStream());
                _OutPut.writeBytes(message + "\n");
                _OutPut.flush();
                _OutPut.close();

            } catch (UnknownHostException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
    trans.start();

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.

Regards,
Gary

Be a part of the DaniWeb community

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