Welcome: Distance Calculator

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 13

Welcome

Distance Calculator
By: Meharaj &

Contents
Abstract Introduction Requirement Specification Data flow diagram Project Task Dijkstra's algorithm Google Distance Matrix

Abstract
Distance Calculator 1 is a Google Map API based Program which accepts Source and
Destination places from where to where he wants to go and returns user the correct solution , i.e. by

going in which way he can save his money as well as time .

Introduction
Google Distance Matrix API
The Google Distance Matrix API is a service that provides travel distance and time for a matrix of origins and destinations. The information returned is based on the recommended route between start and end points, as calculated by the Google Maps API, and consists of rows containing duration and distance values for each pair.

Introduction(cont.)
Dijkstra's algorithm
For a given source vertex (node) in the graph, the algorithm finds the path with lowest cost (i.e. the shortest path) between that vertex and every other vertex. It can also be used for finding costs of shortest paths from a single vertex to a single destination vertex by stopping the algorithm once the shortest path to the destination vertex has been determined.

Requirement Specification
Internet connection : 1mbps JavaScript Enabled Browser : Any

Data flow diagram

Project task
To get input cities from the user. Sending request to the Google server. Getting the responses and storing them into the adjacency matrix. Using dijkstras algorithm finding shortest path between source and destination cities. And presenting the result to user.

Dijkstra's algorithm
// Let V be the set of all vertices in G, and s the start vertex. for(each vertex v){ currentDistance(s-v) = ; predecessor(v) = undefined; For each vertex, the algorithm keeps track of its } current estimated shortest distance from the starting vertex and its predecessor on the currentDistance(s-s) = 0; current path T = V; while(T ){ v = a vertex in T with minimal currentDistance from s; T= T {v}; for(each vertex u adjacent to v and in T){ if(currentDistance(s-u) > currentDistance(s-v) + weight(edge(vu)){ currentDistance(s-u) = currentDistance(s-v) + weight(edge(vu)); predecessor(u) = v; } }}

Dijkstra's algorithm(cont.)
Example
Tracing Dijkstras algorithm starting at vertex B:

The resulting vertex-weighted graph is:

Google Distance Matrix


Requests:
A Distance Matrix API request takes the following form:
http://maps.googleapis.com/maps/api/distancematrix/output?parameters

Required parameters: origins One or more addresses and/or textual latitude/longitude


values, separated with the pipe (|) character, from which to calculate distance and time destinations One or more addresses and/or textual latitude/longitude values, separated with the pipe (|) character, to which to calculate distance and time.

Google Distance Matrix (cont.)


sensor Indicates whether your application is using a sensor
(such as a GPS locator) to determine the user's location. This value must be either true or false.

Optional parameters:
mode specifies the mode of transport to use when calculating
directions. Valid value are:

driving (default) indicates standard driving directions using the road network. walking requests walking directions via pedestrian paths & sidewalks (where available). bicycling requests bicycling directions via bicycle paths & preferred streets (currently only available in the US and some Canadian cities).

References
https://developers.google.com/maps/documentation/distance matrix/#DistanceMatrixRequests http://www.w3schools.com/googleAPI

You might also like