Hello !
I have a task from my university that bothers me and I definately need some help.
I have to create a web app in which i can add locations from the world map by taking the coordinates
and make route between two selected locations from the added. Also the km/h between the two locations must be summed.
Other important and maybe one of the main things is to calculate the total cost summed that you have to pay.
If for example the traveler have 5 congestions and 3 of them are with bus and two are with train this must be calculated.
Finally the path between the two locations have to be highlighted on the google map. Technologies that I have to use
are PHP for the server side among with PGSQL and javascript for the google map api.

Any help and ideas given will be greatly appriciated !

Dani AI

Generated

Building on 's "break it down" advice, here is a compact, practical approach for that turns the assignment into clear, testable pieces: (1) store points and rates in PostgreSQL, (2) use Google Maps JS (DirectionsService / DistanceMatrix) to get legs, distance and duration, (3) send leg data to PHP to persist and compute cost. Clarifying note: summing "km/h" is usually a misunderstanding — sum distances (km) or durations (seconds). Summing speeds is not meaningful; compute average speed instead if needed.

Example schema (Postgres):

CREATE TABLE locations (
  id SERIAL PRIMARY KEY,
  name TEXT,
  lat DOUBLE PRECISION NOT NULL,
  lng DOUBLE PRECISION NOT NULL,
  created_at TIMESTAMP DEFAULT now()
);

CREATE TABLE modes (
  mode TEXT PRIMARY KEY,
  base_cents INT DEFAULT 0,
  per_km_cents INT NOT NULL
);

CREATE TABLE route_legs (
  id SERIAL PRIMARY KEY,
  from_loc INT REFERENCES locations(id),
  to_loc INT REFERENCES locations(id),
  mode TEXT REFERENCES modes(mode),
  distance_m INT,
  duration_s INT,
  polyline TEXT
);

Client-side: request a route, capture legs, then POST them to PHP for storage and cost calculation.

var ds = new google.maps.DirectionsService();
var dr = new google.maps.DirectionsRenderer({map: map});
ds.route({
  origin: {lat: A_lat, lng: A_lng},
  destination: {lat: B_lat, lng: B_lng},
  travelMode: 'TRANSIT' // or 'DRIVING'
}, function(res, status){
  if (status!=='OK') return console.error(status);
  dr.setDirections(res);
  var legs = res.routes[0].legs;
  // collect distance.value (meters) and duration.value (seconds) per leg
  // POST legs to server to persist + compute cost
});

Server-side cost example (PHP pseudo):

function compute_cost(array $legs, PDO $pdo){
  $totalCents = 0;
  $q = $pdo->prepare('SELECT base_cents, per_km_cents FROM modes WHERE mode=?');
  foreach($legs as $leg){
    $q->execute([$leg['mode']]);
    $r = $q->fetch();
    $km = $leg['distance_m']/1000;
    $totalCents += $r['base_cents'] + round($km * $r['per_km_cents']);
  }
  return $totalCents;
}

Quick tips: use DistanceMatrix for many pairwise distances; cache results and store the encoded polyline so maps can be re-rendered without repeated API calls; consider PostGIS when doing spatial queries; explicitly record mode per leg (bus/train) so fares calculate correctly; monitor Google Maps Platform quotas and billing to avoid surprises.

That sounds like a neat idea. I think you'll be busy for months implementing this and getting it all bugged out. But I'm going with advice here. Break down the problem into manageable doable chunks. You have your high level goal but now you get to break it down into components your programming team can handle.

My thought is that you can break down the system to something like a classic design I use which is again high level but has worked for me many times which breaks a system into starting blocks like:

  1. The Interview. The screens that collect the information we need to get to the result.
  2. The Work. Here we use the interveiw answers to get more information and compute the answers for the last stage.
  3. The Report. Here we display, print or show the results.

Sometimes I run into new programmers that forget to break the problem down into chunks, steps or whatever you want to call work units.
Good luck in your assignment. You'll be at this for a long time.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.