Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

How to implement a number of cars and a map in Java and Angular?

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys I'm learning Java and I'm working on a project which I'm not quite sure if it can be accomplished in java
I'm building a rental car manager program(Java backside and then Angular front) which I want to implement a small scale map and show the different car locations on the map and I'm not quite sure how to get it done.
Few leads
1. Add a lan/mul field in each car which later ill implement on web maybe using google maps API?Problem is im not sure how to add a moving object on a map
2.Nop never mind, i only got 1 lead
Any help would be appreciated
 
Saloon Keeper
Posts: 12402
269
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know what you mean by your first lead, but it sounds like you're rushing to implementation before you have a high level plan.

Let's start with the functional requirements:

- Display a map of a geographic area on a webpage.
- Display icons that represent cars on top of the area map at certain locations.
- Update the locations of the icons based on current information.

As I see it, you first have to tackle the problem of displaying a map. The question is, do you already have an image of the area that you want to display, or do you want to retrieve the area map from a third-party service?
 
mike moka
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all thanks for the quick reply and summarising in steps!

Ideally, I would love to just sketch out a map (draw it in paint no need for it to be over-complex because mainly I need 1 starting point, randomize 4/5 routes for 4/5 different cars, 2 "garage" locations, and 1 gathering point) but I wouldn't know even how to start with coding over an image  
so I'm guessing third party service
 
Marshal
Posts: 70598
287
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You still sound as though you were trying to organise implementation details before you have a clear concept of what you are planning to do. Start by creating a description of the problem, but don't copy the assignment you have ben given. What's this about random journeys?
 
Stephan van Hulst
Saloon Keeper
Posts: 12402
269
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you definitely can use your own image, you just have to start by thinking how you will express the locations of cars, and how those locations will map to points on your image.

How big is the area? If it is not so big that you need to take the curvature of the earth into account, you can just come up with your own two-dimensional Euclidean coordinate system and then convert those coordinates to pixels. That is assuming that you're supplying the car locations yourself, and not from some service that provides GPS coordinates. Otherwise you need to perform a little bit of trigonometry; in this case it probably will be easier to use something like Google Maps.

Maybe you can give us a bit more background on the project you're working on. Is it an assignment? Do the locations need to refer to real places, or can they be fictional? If this is an assignment, what is the main thing that it's supposed to teach you?
 
mike moka
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh ok ill expand on my project
This is a personal project, not some assignment with a definite end goal , just need more projects under my belt for the eventual job hunt. I've built a Coupon system(Full-Stack project using Java, Spring boot, SQL Server, Angular) before (so somewhat experienced in java but still a beginner).
As for the project itself. I want to build a Rental car system that would allow a user to view the fleet of available cars, add new cars, and have a realtime view of a map with icons representing the cars.
As for the map itself, I would prefer an X, Y linear map, no need to throw in trigonometry (GOD NO), with predefined Key Locations.
Rough Sketch~
https://ibb.co/87G4v7v

1. I want the cars to start from the same point and then move randomly on the map
2. On certain Mileage points (ex after 50km of travel) the car will search for the nearest garage and move there
3. On a certain button click, all cars will move to the gathering point
4. Different button for cars to go back to starting point and disappear off the map.
 
Stephan van Hulst
Saloon Keeper
Posts: 12402
269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, no need for any third-party service. You can just display the image you drew directly in your client.

Here's a trick: Since your map is so schematic, it lends itself well to a vector graphic format such as SVG. An SVG is just an XML file that contains elements representing shapes and their dimensions and coordinates. There are JavaScript libraries out there that can modify an SVG as it's being displayed in the browser. That means that you can use such a library to add your own shapes on top of the map that is already in the SVG, and you can modify the location of the shapes at runtime. An added bonus is that you can do it all in the coordinate space of the original SVG, and any scaling and translation will be done by your browser automatically as it tries to display an image on the web page.

One such library is D3, which I had really good experiences with. It's quite heavy duty, and there may be simpler libraries that are more suitable to your application, but I'm no expert in the front-end world.

If you agree with this approach, step 1 is to write a very simple web application that only does one thing, but does it well: Display an SVG image on a web page.
 
mike moka
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, sorry for the late reply but I have been researching and I have run into a problem.
First of all, I started with drawing a new map using Tiled and converted it to an SVG file (Just a test map) and displayed it on my website.
Now i need to define my map, and im not sure how to tackle that issuse. I need to have a way to limit (or guide) the car icons ONLY on the road and to act a certain way on certain locations

https://ibb.co/M1QHqmr
 
Stephan van Hulst
Saloon Keeper
Posts: 12402
269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Separate the map drawing logic from the behavior of the cars.

First, I see that your map has two-way streets (possibly with multiple lanes, I'm not sure?), crossings and dead ends. How do the cars behave in these locations? How does a car know that it is in such a location? Do you have direct control over the cars or do you only guide them in some way? How do you guide them?
 
mike moka
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EDIT  to the map to somewhat simplify it
https://ibb.co/VCgmNRV

My intention is to make it a 2-way street (1 lane), 5 key locations which are a start position(same as end, bottom end), 2 Garage locations (marked G), a random location, and a parking location (marked movie).
1. On a button click a car will appear at the starting location
2. The car hopefully moves on a random course (If not possible or over complex than a set route will be ok)
3. On certain milage (pre-set for all cars, let's say after 50 km) the car should seek the nearest garage and enter it. (G1 or G2)

And this is why I'm stuck, I have no idea how to code a map or a route, should every pixel have a coordinate which will say if, on x1,y2 move to x1,y2  and on certain checks go to per set coordination?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic