开发者

send lat and long using open socket

开发者 https://www.devze.com 2023-03-05 22:10 出处:网络
I want to send this开发者_JS百科 Lat and Long the gps current locationon my open socket between my android and my python server .

I want to send this开发者_JS百科 Lat and Long the gps current location on my open socket between my android and my python server .

public void onLocationChanged(Location loc)
{
    GeoPoint point = new GeoPoint((int) (loc.getLatitude() * 1E6),
                (int) (loc.getLongitude() * 1E6));      
    String Text = "My current location is: " +
            "Latitud =" + loc.getLatitude()+ 
            "Longitud =" +loc.getLongitude() ;
    Toast.makeText(getApplicationContext(), 
            Text, 
            Toast.LENGTH_SHORT).show();
}

so i save it on string text and i add button to connect it to the server now i want to send the lat and lang each time so how to send this string using the open socket ??


String cmd("my command");
    try {
        InetSocketAddress address = new InetSocketAddress("10.1.1.1", 12350);
        DatagramPacket request = new DatagramPacket(cmd.getBytes(), cmd.length(), address);
        DatagramSocket socket = new DatagramSocket();
        socket.send(request);
    } catch (SocketException e) {

        ...
        }
    } catch (IOException e) {

       ...
        }
    }


On the right side of the current screen I'm looking at is a section called "Related". In that section, the first link is to android open socket and send commands

Also, searching on StackExchange for android sockets nets a good number of past questions and answers on the topic, including Using Sockets to send and receive data.

Does this answer your question?

0

精彩评论

暂无评论...
验证码 换一张
取 消