Click here to Skip to main content
16,016,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi friends
i developed application in smart device for reading GPS Data (latitude and longitude) from serial port i can get latitued and longitude my next task is SAVE the GPS dat in server and show postion using latitude and longititude
Posted
Updated 25-Feb-10 1:02am
v3
Comments
Member 10365664 23-Jul-18 6:14am    
Please share your code which you have developed..for reading data

1 solution

Your question does not really outline the details of how you want to transmit the data, but if you want to go for a dead simple solution you could have a socket open on the server listening for incoming connections sending the data in any format you like.

So a desktop application looking something like:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Threading;
using System.IO;
using System.Net;

namespace Server {
    class Program  {
        private Thread thread;
        private Socket serverSocket;
        private bool active;

        public Program() {
            IsActive = true;
            serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            serverSocket.Bind(new IPEndPoint( IPAddress.Any, 4242));
            serverSocket.Listen(4);
            thread = new Thread(AcceptMethod);
            thread.Start();
        }

        private void AcceptMethod() {
            try {
                while (IsActive) {
                    Console.Write("Waiting for client connection...");
                    Socket clientSocket = serverSocket.Accept();
                    Console.WriteLine("{0} connected!", clientSocket);
                    StringBuilder builder = new StringBuilder();
                    while (clientSocket.Connected && clientSocket.Available > 0) {
                        byte[] buffer = new byte[32];
                        int read = clientSocket.Receive(buffer);
                        builder.Append(Encoding.UTF8.GetString(buffer, 0, read));
                    }
                    Console.WriteLine("Read message: {0}", builder);
                    clientSocket.Close();
                }
            }
            catch (Exception e) {
                Console.WriteLine("Error: {0}", e.Message);
            }
        }

        public bool IsActive {
            get { return active; }
            set {
                active = value;
                if (!IsActive)
                {
                    serverSocket.Close();
                }
            }
        }

        static void Main(string[] args) {
            Program program = new Program();
            Console.ReadLine();

            program.IsActive = false;
        }
    }
}



And a client application running on the device looking something like:

C#
private void sendButton_Click(object sender, EventArgs e) {
    string host = serverAddress.Text.Split(':')[0];
    int port = Convert.ToInt32(serverAddress.Text.Split(':')[1]);
    TcpClient client = new TcpClient(host, port);

    byte[] buffer = Encoding.UTF8.GetBytes(String.Format("ClientId={0};Latitude={1};Longitude={2}", clientId.Text, latitude.Text, longitude.Text));
    client.GetStream().Write(buffer, 0, buffer.Length);
    client.Close();
}



Then, on the server side you could parse the message sent from the client to the server and store that in a file or in a DB or where ever you want.

Note that this is just an example to get you going, for an actual application you'd probably want to consider things like security as well, and more than likely use a http based approach instead.

As for showing it on a map, I'd look into the Google maps api or something similar.

Hope this helps,
Fredrik Bornander
 
Share this answer
 
Comments
Member 13343979 10-Oct-17 22:18pm    
how we using mobile GPS to transfer latitude and longitude from smart phone to computer system??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900