Featured in Mybridge’s Top Ten NodeJS articles from October 2016 and Top Ten NodeJS articles of the year (v.2017)
Update: Check-out the latest version on my tech blog!
This article is now a few years old - and due to JavaScript's rapidly changing ecosystem, the article has become slightly outdated. Click on the above link for the updated version of this article and the project.
This article is now a few years old - and due to JavaScript's rapidly changing ecosystem, the article has become slightly outdated. Click on the above link for the updated version of this article and the project.
Uber (if you haven’t heard of it) is a handy app that allows you to catch a cab without walking around to look for one. And most importantly, it solves the problems of demand and supply that exists among cab drivers and cab seekers.
Today, there are a variety of startups focused around Uber-for-X apps. The thinking goes that, what Uber did for cabs, they can surely do for other supply/demand problems.
So during a hackathon, me and my friend decided to build a citizen-cop app. We figured it would be cool to build something that can help your friends in times of trouble!
Jan 24, 2019 Open source Uber #deleteuber. Contribute to ro31337/libretaxi development by creating an account on GitHub. Contribute to ro31337/libretaxi development by creating an account on GitHub. Skip to content. Features → Code review. If nothing happens, download GitHub Desktop and try again. Launching GitHub Desktop. Jul 30, 2013 T Dispatch released the code for its taxi booking app, an add-on to their web-based dispatch system. It is designed to make it easier and more affordable for taxi and chauffeur companies of all sizes to implement a customized app of their own. Interview with CTO Tiago Pita: how they got started and why it was important to release their code. Oct 22, 2016 Download this package.json file and save it in the root of your project folder (make sure you named it package.json). To help people learn to code for free. We accomplish this by creating thousands of videos, articles, and interactive coding lessons - all freely available to the public. About Alumni Network Open Source Shop Support.
After some thinking, these were the following features that we agreed upon:
- Civilians will be able to request the nearest police officer in their neighborhood at the press of a button. It’ll raise a ‘distress signal’ and alert nearby cops.
- Any police in the vicinity will immediately receive the user’s location and can choose to accept the request and solve the issue.
- A rating system
- Data collected from locations, crime cases solved, etc. can be visualized on a map, or graphed with some other cool user interface widgets
In this tutorial, I’ll walk you through how we built it step-by-step, so that you’ll be able to build your own Uber-for-X app.
Before you begin, it would help to keep the following points in mind --
- This tutorial will not focus on how to build the app for scale. Or for performance. It’s basically designed so that you can have fun while building it, and how you can create something that mimics Uber. Think of this as though building a Minimum Viable Product to demonstrate your idea or startup, for a proof-of-concept.
- Since I’ve not worked on Android or iPhone apps much, I’ll be building this to work inside a browser.
Now, every app that you build has few important pieces:
- a client-facing app (that you see in a browser or on your phone screens)
- on the back end, a web-server to handle incoming requests from the client and to route information
- and a database to store and query information.
On the back end, you’ll use MongoDB as your database. it’s easier to learn, and offers a lot of querying techniques to handle geospatial information, which you’ll need for your app.
You’ll use NodeJS for your back end logic. Because it’s the same language for both front-end and back-end you wouldn’t have to worry about learning a new language or syntax.
On the front end, you’ll use HTML5, CSS3, JavaScript, and also the Google Maps and Places APIs.
I’m assuming that you already have a working knowledge of JavaScript, and that you have at least a theoretical understanding of how NodeJS and MongoDB work.
Here are the contents of this tutorial :
Part 1 (what you’re reading right now):
- MongoDB Schema design
- Using the Mongo Shell to query information
- Connecting your database with your Node-Express server and writing RESTful APIs
Part 2:
- Using Socket.IO to enable the cop and civilian devices talk to each other
- Using Google Maps API to show civilians and cops on a map
Let’s get started!
Intellget Taxi Open Source Code Download Free
Developers have used MongoDB to build applications for quite some time now. It has a shallow learning curve, and its versatility allows developers to rapidly build applications with ease.
I personally like MongoDB because it allows me to quickly build prototypes for an idea to demonstrate proof-of-concept.
Jan 24, 2014 How to Unlock ANY Motorola for FREE FreeUnlocks.com. That is, TrialPay subsidizes the cost of your code, so you GET IT FREE as a 'thank you' for completing the offer. How To Unlock Moto E. We Can Unlock Your Motorola Moto E Cell Phone for FREE, regardless of what network it is currently locked to! Our Motorola unlocks by remote code (no software. How to unlock Motorola Moto E. The unlocking procedure is very basic, just follow these steps and your device will be network free. Start the device with a simcard different than the one that works in your Motorola Moto E. (Your device works with AT&T, insert a T-Mobile simcard) 2. Message input unlock code should appear (if for any reason the device shows a message Contact operator. Verizon moto e unlock code.
Before you begin, do make sure that you have MongoDB and NodeJS installed. At the time of writing this article, the current version of MongoDB is 3.2.
Designing the Schema
Since you’re using MongoDB, everything that you save in it is a collection of documents.
Let’s create a collection called citizensData for storing citizen information, and another collection called policeData for storing cops info. So go ahead, open up your terminal and type mongo to fire up the mongo shell. Once it opens up, you can show existing databases in MongoDB by typing:
Sic code list download free. SIC Code List - Complete reference in Excel spreadsheet form for FREE. Download it here now.
You need a new database to store your app data. Let’s call it myUberApp. To create a new database, you can type:
The use command has the effect of creating a new database if it doesn’t exist. If it does, it tells Mongo to apply all following commands to this database.
Mongo stores documents in collections. Collections are like tables. To see existing collections, type:
For the cop, the username could be the badge-id too. You might add in a field for email address and one for password too (which won’t be revealed) for authentication purposes.
Go to this link, and save the JSON data-set for cop related information.
To import data from this JSON file, type this in your terminal :
Now, before you start querying your database, you need to learn a little on how indexes in MongoDB (or any database for that matter) work.
An index is a special arrangement of data or data structure that allows you to query for information very efficiently. That way you can quickly retrieve results without having to scan across the entire database.
Intellget Taxi Open Source Code download free. full
For example — let’s say you stored student related information in ascending order of their name in a book, which means that you have an index on the name field. That way, if you had to fetch information of a person named Tyrion, you can quickly locate his information without going through the rest of the students first.
But if you saved the same information in ascending order of their height, then querying information for a person using their name would become difficult. It could take lot of time, because now the students are not saved in order of their names, so you might have to scan and search across multiple rows.
But other kind of queries become possible. For example, fetch information of students whose heights lie between 4 and 5 feet. In which case Tyrion’s info could be retrieved quickly, because:
Different databases support different types of indexes. You could read on the complete list of indexes that supports MongoDB here.
So, now if you type this command:
which will return you all the documents that exist inside the policeData collection — which is the entire list of cops. (The pretty function makes the output easier to read).
If you want to fetch information about a particular cop whose userId is 01, you can type out
db.policeData.find({userId: “01”}).pretty()
Using MongoDB geospatial indexes
Geospatial indexes allow you to store GeoJSON objects within documents.
GeoJSON objects can be of different types, such as Point, LineString and Polygon.
If you observe the output of your .find() command, you’ll notice that every location is an object which has the type field and the coordinates field within it. This is important, because if you store your GeoJSON object as a Point type, you can use the $near command to query for points within certain proximity for a given longitude and latitude.
To use this, you need to create a 2dsphere index (which is a geospatial index) on the location field, and have a type field within it. The 2dsphere index supports queries that calculate geometries on an earth-like sphere. This includes MongoDB geospatial queries: queries for inclusion, intersection and proximity.
So type this in your mongo shell:
Now, to fetch documents from nearest to furthest from a given pair of co-ordinates, you need to issue a command with this syntax :
$minDistance and $maxDistance are optional fields. Now, to get all cops that are located within 2 kilometers from latitude 12.9718915 and longitude 77.64115449999997, run this :
And that’s it — you’ll find a list of documents returned in the output!
Perfect! Now let’s try doing the same with a web server. Download this package.json file and save it in the root of your project folder (make sure you named it package.json), and then in your terminal, cd to the directory that contains the file and run
A brief explanation about some of the packages that you’re going to use :
- Express is a web framework for NodeJS. It has lots of APIs, utilities and middlewares in its ecosystem to help you build your application.
- body-parser parses incoming request bodies in a middleware before your handlers, available under the req.body property. You need this so you can handle POST requests.
- underscore makes writing JavaScript simpler. Feel free to use another library if you prefer.
- socket.io lets you use web sockets within your Node application.
- mongodb is the official NodeJS driver for MongoDB. It helps your Node app talk to your database.
The package.json file contains other modules as well. You’ll need them while building a complete app, but I’ll focus on how to use the mongodb driver in your express app to execute queries. Here’s what some of the other modules do :
- async is a utility for dealing with asynchronous code in NodeJS. It helps you avoid callback hell.
- debug is a debugging library. This handy tool helps debug your programs without the use of ugly console.log statement outputs.
- redis is similar to the mongodb driver. It lets your NodeJS app talk to your Redis database.
- connect-redis is a session store that uses Redis to manage sessions. You’ll need this later when you decide to have user accounts.
Before you write code, it’ll be helpful to organize it first. For now, you can use two files:
- A file for writing your API endpoints
- A file that uses database drivers for database related operations. The route-handler would decide which function to call from the database file. Once a query is performed, the results are returned back to your route-handler with the help of a callback function.
Let’s see how this looks like when you write your code:
In this example, you create a new instance of the MongoClient object from the mongodb module. Once the web server begins, you connect to your MongoDB database using the connect function that’s exposed by your MongoClient instance. After it initializes the connection, it returns a Db instance in the callback.
You can now pass both the app and db instances to the initialize function of your routes.js file.
Intelligent Taxi Open Source Code Download Free Tv F
Next, you need to create a new file called routes.js, and add this code:
Intellget Taxi Open Source Code Download Free Pc
For this to work, you’ll have to pass the coordinates as query strings in your request. You’ll also write your database operations in another file. So go ahead and create a new file db-operations.js, and write this:
This function accepts three arguments: an instance of db, an array that contains co-ordinates in the order [<longitude>,<latitude>], and a callback function, to which it returns the results of your query.
The createIndex ensures that an index is created on the specified field if it doesn’t exist, so you may want to skip that if you have already created an index prior to querying.
Now, all that’s left to do is to call this function inside your handler. So modify your routes.js code to this:
And that’s it! Run
from your terminal, then open your browser and hit http://localhost:8000/cops?lat=12.9718915&&lng=77.64115449999997
Depending on the query strings that you passed, you should either get a JSON response containing an empty array or an array containing cop data!
This is the end of Part 1. In Part 2, you’ll take it up a notch and try to send a distress signal to nearby cops. Then you’ll figure out how a cop could respond back to the signal using socket.io. You’ll also see how to display the location of the citizen on a map.
In the meantime do have a look at the source code on Github!
If you liked this article, please consider supporting me on Patreon.
You should totally subscribe. I won't waste your time.
Many thanks to Quincy Larson for helping me make this article better.
You can read this article and subsequent parts in my blog too!
Featured in Mybridge’s Top Ten NodeJS articles from October 2016 and Top Ten NodeJS articles of the year (v.2017)