Skip to main content

Displaying Routes - Using JXMapKit

13 replies [Last post]
pret123
Offline
Joined: 2009-11-14
Points: 0

Hello All,

I'm using swingx-ws library to display the map component of my project (a desktop application, using Swing). As one of the requirements, I need to display Routes on the maps. The routes need to be shown as real routes and not just straight lines connecting two points (which would be far easy to implement).

Question:
Is there any library/source which calculates the route and gives a set of waypoints, given the start and end point as lat/lon pair?

I use OpenStreetMaps as the map provider.

Any clues will be greatly appreciated.
Thanks in advance.
-Pret

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
whycantiusesymbo
Offline
Joined: 2012-08-08
Points: 0

Hello pret123,

Now I am working on drawing a straight line connecting two cities, would you help me with it?

Thanks

ahenao59
Offline
Joined: 2010-11-10
Points: 0

Hello, you say it is far easy to implement a straight line between two points. I'm not very expert with swingx neither with graphics2D. Any advice?

Thank you a lot.

samuelrobert
Offline
Joined: 2004-06-25
Points: 0

Do you have results ? I may be interested.

You may also try www.jalamap.org, an open-source java layer for Mappy web
services, providing geocoding and routing functions. (A free account on api.mappy.com is necessary to use it)

Regards,
Sam.

pret123
Offline
Joined: 2009-11-14
Points: 0

Hello Sam,

Sorry for the delayed response.

I am now able to paint the real routes on the map. But, I am not using YOURS. The data from YOURS is highly inconsistent and the server times out more often than not. I now fetch routes from http://routes.cloudmade.com. The data is pretty accurate and reliability is high.

You will get a xml as a response, which has the co-ordinates of every turn. You simply have to draw lines between each co-ordinate.

Also, the service needs a registration on their site (to get an api key) and it is free.

By the way, looks like jalamap.org doesn't give routes.

Good luck,
-Pret

doantranthanh
Offline
Joined: 2011-01-07
Points: 0

Hi pret123,

I am doing my MSc dissertation, also need to deploy route services on OSM map. Could you give me some advice about it? I have no ideas how to do at this time.

Thank you very much.

alxcer
Offline
Joined: 2010-04-22
Points: 0

Can you tell me what library / class you use to load a .gpx file (from the local machine). Any code example would help.

cganoe
Offline
Joined: 2009-09-05
Points: 0

I'm not entirely clear on what you're asking. If you're talking about computing and displaying the path on actual roads between two points, I'd love to be able to do that too, but that's really outside the scope of swingx-ws. Swingx-ws just gets the map as graphical tiles from the OpenStreetMaps server. It doesn't know anything about the actual roads on the map.

If you're just talking about displaying a known path between two points rather than a straight line, I have some code that takes a GPX file and displays it on the map viewer. It's just an overlay painter, so if you've been working with swingx-ws this should be obvious. I'm slowly starting to put together a library for managing features on the map, but it's not there yet.

I suspect there's a way to get road data from the OpenStreetMaps server and/or request their server to display a route or routes in with the tiles, but neither are supported in swingx-ws. If you can find some documentation on how to control what gets displayed on the OpenStreetMaps tiles, it would probably not be hard to change the swingx-ws code to pass these commands long with the tile requests.

pret123
Offline
Joined: 2009-11-14
Points: 0

Thanks for your reply cganoe.

[b]I am looking for something that can compute and display routes on actual roads! [/b]

My first try was to use the overlay Painter. But unfortunately it is too difficult to adapt it to user pan and zoom. If there is a way to simply obtain tiles from OSM, with routes painted on them it would be great. I did not find means. Not even sure if OSM has one such feature :-( Does any one know?

Controlling the display on tiles, should not be difficult from what I see (swingx-ws is so flexible). Right now I'm trying to find if can use OSMNavigation with swingx-ws (http://sourceforge.net/apps/mediawiki/travelingsales/index.php?title=OSM...)

swebb99
Offline
Joined: 2007-06-26
Points: 0

I wrote my own routing engine using the ITN data from Ordanance Survey and then used and overlay painter. I didn't have a problem with zooming or panning, it was very easy! Saying that I have re-written a lot of the mapping code provided by JXMapViewer to aid use of development.

cganoe
Offline
Joined: 2009-09-05
Points: 0

OK, well I don't have any problems getting overlay painter to handle pan and zoom. Not sure what your issue is there. Like I said, I have code that displays a GPX file as a line painter overlay on the map, and I can pan/zoom it.

I looked some more at how OpenStreetMap generates tiles and this is all generated in advance and cached at the server, so there is no way to do that at the tile level from their server directly. I was thinking about something like MapServer (mapserver.org) where you can add/manipulate style info on the map tiles via the URL.

It looks like you could use Clopin (http://wiki.openstreetmap.org/wiki/Clopin) to generate your own OpenStreetMap tiles with routes, but this would be done locally on the client.

I'm not familiar with OSMNavigation, but it looks like a good approach. You should (depending on what their API supports) be able to get the vectors for the route and turn them into a JXMapKit overlay. They also rely on local data, but it's vector data.

I tried to run the OSMNavigation application, but it kept getting stuck on the screen that should let me download the ".osm" data file. Are only certain locations supported despite what's in the download tree listing?

You could also look at what http://www.openrouteservice.org/ does since it's based on OpenStreetMap.

pret123
Offline
Joined: 2009-11-14
Points: 0

Hello cganoe,

Sorry for such a delayed response. Was sick. Wasted a lot of time doing nothing and now I ran out of time.

I'm looking to just display a GPX on screen and get done with it for now (to meet deadlines). But I have a noobish question there. Given a source and destination (as lat/lon pairs), which depends on user interaction, is there any opensource GPS data provider? A server to whom I can talk to? I mean, where do you get the GPX file from?

About running the OSM navigation, I guess you should make your JVM give more memory to the application at run-time. And, also, it does support only a few locations.

TIA.

pret123
Offline
Joined: 2009-11-14
Points: 0

I guess I was a bit hasty in asking for a GPS data source before doing a complete search. I found that YOURS (http://wiki.openstreetmap.org/index.php/YOURS#Routing_API) provides the service.

I haven't yet checked if it works. Will post results if anybody is interested.

cganoe
Offline
Joined: 2009-09-05
Points: 0

Great find! I had not seen yournavigation.org. Looks like it should be easy to do something with this. One more thing for my to-do list. Not a lot of support for street addresses though, from what I see.

My GPX data was from my personal GPS unit.