Featured in Mybridge’s Top Ten NodeJS articles from October 2016 and Top Ten NodeJS articles of the year (v.2017)
Jun 25, 2019 Download Gofer - The Best Uber clone App for free. Trending features of Uber Clone Script. With App like Uber Clone, You can start your own ondemand taxi booking business. With all the trending features, you can easily start your own business with option to add your own idea as customization is available with our apps. We successfully launched many taxi apps for clients. To buy our HireMe uber clone app source code, drop an email and our team will contact you then we will deploy both driver and passenger app over ios/android free-of-cost on your servers/app stores. Besides this, the backend database and admin panel are hosted on an AWS server.
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.
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! Indian penal code 1860 in gujarati free download.
After some thinking, these were the following features that we agreed upon:
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 —
Now, every app that you build has few important pieces:
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):
Part 2:
Let’s get started!
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.
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:
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.
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 :
Uber Clone Script
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 :
![]()
Before you write code, it’ll be helpful to organize it first. For now, you can use two files:
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.
Next, you need to create a new file called routes.js, and add this code:
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.
Uber Clone Source Code Free Download For Windows 7
Many thanks to Quincy Larson for helping me make this article better.
Uber Clone Source Code Free Download 32 Bit
You can read this article and subsequent parts in my blog too!
Best Uber CloneFeatured in Mybridge’s Top Ten NodeJS articles from October 2016 and Top Ten NodeJS articles of the year (v.2017) Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |