A location tracking application is where a developer really understands the concept of real time communication between client and server. I made LocalTrack - an application which tracks location data of a driver and the passengers registered for that drive can see the location on the map in real time.
The basic idea is that the driver and passengers have applications installed to their phone. The driver presses start button on his app, and the application begins to send lat-long data to the server. The server then processes the data like publish-subscribe model and updates the location to all the subscribers(passengers).
The aim is to display real time location on google map just like Uber does. But of course factors such as battery consumption, accuracy, latency etc make it really hard especially in a react native application.
When a javascript developer thinks about real time communication, the first thing which crosses his mind is using websockets and so did I. If you come from a low level language(C, C++, Java) background, you would be familiar with (native)sockets. But websockets are different. These 'http sockets' use http requests under the hood with long response time and multiple of those requests to create an persistent client server connection. Since websockets use http requests, thinking about implementing UDP protocol is, well pointless, but more on this later.
The basic idea is that the driver and passengers have applications installed to their phone. The driver presses start button on his app, and the application begins to send lat-long data to the server. The server then processes the data like publish-subscribe model and updates the location to all the subscribers(passengers).
The aim is to display real time location on google map just like Uber does. But of course factors such as battery consumption, accuracy, latency etc make it really hard especially in a react native application.
When a javascript developer thinks about real time communication, the first thing which crosses his mind is using websockets and so did I. If you come from a low level language(C, C++, Java) background, you would be familiar with (native)sockets. But websockets are different. These 'http sockets' use http requests under the hood with long response time and multiple of those requests to create an persistent client server connection. Since websockets use http requests, thinking about implementing UDP protocol is, well pointless, but more on this later.
Socet.IO is an event based communication library for node.js, it uses Websockets and is divided into client and server parts. We are going to use Socket.IO because of its seamless broadcast capabilty and works reliably on different platforms.
We are going to implement all this in React Native. Socket.IO-client works well with React Native. React Native is designed in such a way that it is possible for us to write real native code in Java or Swift, and this enables us to again think about using native sockets instead of Socket.IO. Although after talking so much about it, it is still relevant to ditch Socket.IO because native sockets are really fast and support UDP.
Why UDP?
Well, UDP is really helpful in achieving what we are aiming for in this project. That is, broadcasting location. UDP is connection-less, that means we do not expect any acknowledgement of the data packet we just sent over the network. While this drastically improves the performance, it reduces the reliability of our application. Well implementing native sockets is really an after thought and out of scope of this project.
Anyways, now we require an approach to display the location on (google) maps. We will use react-native-maps for this. Google maps require an API key which can be retrieved by following the documentation. Make sure you apply for 'Maps SDK for Android', or IOS.
Well this was a briefing about what we are actually going to do, and the idea behind it, we will begin implementing these step by step in the next blog.
We are going to implement all this in React Native. Socket.IO-client works well with React Native. React Native is designed in such a way that it is possible for us to write real native code in Java or Swift, and this enables us to again think about using native sockets instead of Socket.IO. Although after talking so much about it, it is still relevant to ditch Socket.IO because native sockets are really fast and support UDP.
Why UDP?
Well, UDP is really helpful in achieving what we are aiming for in this project. That is, broadcasting location. UDP is connection-less, that means we do not expect any acknowledgement of the data packet we just sent over the network. While this drastically improves the performance, it reduces the reliability of our application. Well implementing native sockets is really an after thought and out of scope of this project.
Anyways, now we require an approach to display the location on (google) maps. We will use react-native-maps for this. Google maps require an API key which can be retrieved by following the documentation. Make sure you apply for 'Maps SDK for Android', or IOS.
Well this was a briefing about what we are actually going to do, and the idea behind it, we will begin implementing these step by step in the next blog.
Comments
Post a Comment