B4J Question OpenRoute or OpenStreetMap - how to use?

DarkoT

Active Member
Licensed User
Hi guys,
I need to create small desktop application which will show the users some direction between two points on map. User need to input first adress and second adress and I will show him the road from start to end point.
I found API for this on OpenRoute or OpenStreet Map (okey, basicaly I can use google maps but is not free)... In any case - I can get info from Api with next code:

Api:
Dim Link As String = "https://api.openrouteservice.org/geocode/search?api_key=5b3ce3597851110001cf6248c9fa82847ccd4fc39a876be87bc92830&text=wien&boundary.country=AT&sources=openstreetmap"

    Dim j As HttpJob
    j.Initialize("j", Me)
    j.poststring(Link, "")
    j.GetRequest.SetHeader("Accept", "application/json, application/geo+json, application/gpx+xml, img/png; charset=utf-8")
    wait for (j) jobdone (j As HttpJob)
    
    ' if is sucess
    If j.Success Then
        Log(j.GetString)
    Else
        Log(j.ErrorMessage)
    End If
    j.Release

I recived this response - In Json:

Json response:
{"geocoding":{"version":"0.2","attribution":"https://openrouteservice.org/terms-of-service/#attribution-geocode","query":{"text":"wien","size":10,"sources":["openstreetmap"],"layers":["venue","street"],"private":false,"boundary.country":["AUT"],"lang":{"name":"English","iso6391":"en","iso6393":"eng","via":"default","defaulted":true},"querySize":20,"parser":"pelias","parsed_text":{"subject":"wien","locality":"wien"}},"warnings":["performance optimization: excluding 'address' layer"],"engine":{"name":"Pelias","author":"Mapzen","version":"1.0"},"timestamp":1637692353179},"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[16.336282,48.196545]},"properties":{"id":"node/60093107","gid":"openstreetmap:venue:node/60093107","layer":"venue","source":"openstreetmap","source_id":"node/60093107","name":"Wien Westbahnhof","confidence":1,"match_type":"exact","accuracy":"point","country":"Austria","country_gid":"whosonfirst:country:85632785","country_a":"AUT","region":"Vienna","region_gid":"whosonfirst:region:85681667","region_a":"WI","localadmin":"Wien","localadmin_gid":"whosonfirst:localadmin:1108838101","locality":"Vienna","locality_gid":"whosonfirst:locality:101748073","neighbourhood":"Westbahnhof","neighbourhood_gid":"whosonfirst:neighbourhood:85898759","continent":"Europe","continent_gid":"whosonfirst:continent:102191581","label":"Wien Westbahnhof, Vienna, Austria","addendum":{"osm":{"wheelchair":"yes","wikidata":"Q698145","wikipedia":"de:Wien Westbahnhof","operator":"ÖBB-Infrastruktur AG"}}}},{"type":"Feature","geometry":{"type":"Point","coordinates":[16.377855,48.18501]},"properties":{"id":"node/1839787470","gid":"openstreetmap:venue:node/1839787470","layer":"venue","source":"openstreetmap","source_id":"node/1839787470","name":"Wien Hauptbahnhof","confidence":1,"match_type":"exact","accuracy":"point","country":"Austria","country_gid":"whosonfirst:country:85632785","country_a":"AUT","region":"Vienna","region_gid":"whosonfirst:region:85681667","region_a":"WI","localadmin":"Wien","localadmin_gid":"whosonfirst:localadmin:1108838101","locality":"Vienna","locality_gid":"whosonfirst:locality:101748073","neighbourhood":"Favoriten","neighbourhood_gid":"whosonfirst:neighbourhood:85898653","continent":"Europe","continent_gid":"whosonfirst:continent:102191581","label":"Wien Hauptbahnhof, Vienna, Austria","addendum":{"osm":{"wheelchair":"yes","wikidata":"Q697300","wikipedia":"de:Wien Hauptbahnhof","operator":"ÖBB-Infrastruktur AG"}}}},{"type":"Feature","geometry":{"type":"Point","coordinates":[16.367778,48.260228]},"properties":{"id":"node/3488369063","gid":"openstreetmap:venue:node/3488369063","layer":"venue","source":"openstreetmap","source_id":"node/3488369063","name":"Wien Nußdorf","confidence":1,"match_type":"exact","accuracy":"point","country":"Austria","country_gid":"whosonfirst:country:85632785","country_a":"AUT","region":"Vienna","region_gid":"whosonfirst:region:85681667","region_a":"WI","localadmin":"Wien","localadmin_gid":"whosonfirst:localadmin:1108838101","locality":"Vienna","locality_gid":"whosonfirst:locality:101748073","neighbourhood":"Nussdorf","neighbourhood_gid":"whosonfirst:neighbourhood:85898361","continent":"Europe","continent_gid":"whosonfirst:continent:102191581","label":"Wien Nußdorf, Vienna, Austria","addendum":{"osm":{"wikidata":"Q18762414","wikipedia":"de:Bahnhof Wien Nußdorf","operator":"ÖBB-Infrastruktur AG"}}}},{"type":"Feature","geometry":{"type":"Point","coordinates":[16.36089,48.213006]},"properties":{"id":"relation/1441683","gid":"openstreetmap:venue:relation/1441683","layer":"venue","source":"openstreetmap","source_id":"relation/1441683","name":"Universität Wien","housenumber":"1","street":"Universitätsring","postalcode":"1010","confidence":1,"match_type":"exact","accuracy":"point","country":"Austria","country_gid":"whosonfirst:country:85632785","country_a":"AUT","region":"Vienna","region_gid":"whosonfirst:region:85681667","region_a":"WI","localadmin":"Wien","localadmin_gid":"whosonfirst:localadmin:1108838101","locality":"Vienna","locality_gid":"whosonfirst:locality:101748073","neighbourhood":"Hofburg","neighbourhood_gid":"whosonfirst:neighbourhood:85898679","continent":"Europe","continent_gid":"whosonfirst:continent:102191581","label":"Universität Wien, Vienna, Austria","addendum":{"osm":{"wikidata":"Q19971231","wikipedia":"de:Hauptgebäude der Universität Wien","website":"https://www.univie.ac.at/"}}},"bbox":[16.3590774,48.2123003,16.3612496,48.2139265]},{"type":"Feature","geometry":{"type":"Point","coordinates":[16.350026,48.247491]},"properties":{"id":"way/385797837","gid":"openstreetmap:venue:way/385797837","layer":"venue","source":"openstreetmap","source_id":"way/385797837","name":"Karmelitenkonvent Wien","housenumber":"35","street":"Silbergasse","postalcode":"1190","confidence":1,"match_type":"exact","accuracy":"point","country":"Austria","country_gid":"whosonfirst:country:85632785","country_a":"AUT","region":"Vienna","region_gid":"whosonfirst:region:85681667","region_a":"WI","localadmin":"Wien","localadmin_gid":"whosonfirst:localadmin:1108838101","locality":"Vienna","locality_gid":"whosonfirst:locality:101748073","neighbourhood":"Dobling","neighbourhood_gid":"whosonfirst:neighbourhood:85904321","continent":"Europe","continent_gid":"whosonfirst:continent:102191581","label":"Karmelitenkonvent Wien, Vienna, Austria","addendum":{"osm":{"wikidata":"Q1734055","wikipedia":"de:Karmelitenkloster Döbling","website":"http://wien.karmel.at/"}}},"bbox":[16.3495683,48.2471502,16.3503436,48.247675]},{"type":"Feature","geometry":{"type":"Point","coordinates":[16.376653,48.194928]},"properties":{"id":"way/162606842","gid":"openstreetmap:venue:way/162606842","layer":"venue","source":"openstreetmap","source_id":"way/162606842","name":"AK Wien","housenumber":"20-22","street":"Prinz-Eugen-Straße","postalcode":"1040","confidence":1,"match_type":"exact","accuracy":"point","country":"Austria","country_gid":"whosonfirst:country:85632785","country_a":"AUT","region":"Vienna","region_gid":"whosonfirst:region:85681667","region_a":"WI","localadmin":"Wien","localadmin_gid":"whosonfirst:localadmin:1108838101","locality":"Vienna","locality_gid":"whosonfirst:locality:101748073","neighbourhood":"Belvedere","neighbourhood_gid":"whosonfirst:neighbourhood:85898645","continent":"Europe","continent_gid":"whosonfirst:continent:102191581","label":"AK Wien, Vienna, Austria","addendum":{"osm":{"wheelchair":"yes"}}},"bbox":[16.3755555,48.1944249,16.3768113,48.1954201]},{"type":"Feature","geometry":{"type":"Point","coordinates":[16.385987,48.2078]},"properties":{"id":"node/253157427","gid":"openstreetmap:venue:node/253157427","layer":"venue","source":"openstreetmap","source_id":"node/253157427","name":"Handelsgericht Wien","housenumber":"1a","street":"Marxergasse","postalcode":"1030","confidence":1,"match_type":"exact","accuracy":"point","country":"Austria","country_gid":"whosonfirst:country:85632785","country_a":"AUT","region":"Vienna","region_gid":"whosonfirst:region:85681667","region_a":"WI","localadmin":"Wien","localadmin_gid":"whosonfirst:localadmin:1108838101","locality":"Vienna","locality_gid":"whosonfirst:locality:101748073","neighbourhood":"Landstraße","neighbourhood_gid":"whosonfirst:neighbourhood:85898697","continent":"Europe","continent_gid":"whosonfirst:continent:102191581","label":"Handelsgericht Wien, Vienna, Austria","addendum":{"osm":{"wheelchair":"yes"}}}},{"type":"Feature","geometry":{"type":"Point","coordinates":[16.35725,48.206842]},"properties":{"id":"node/3425352392","gid":"openstreetmap:venue:node/3425352392","layer":"venue","source":"openstreetmap","source_id":"node/3425352392","name":"Oberlandesgericht Wien","housenumber":"11","street":"Schmerlingplatz","postalcode":"1011","confidence":1,"match_type":"exact","accuracy":"point","country":"Austria","country_gid":"whosonfirst:country:85632785","country_a":"AUT","region":"Vienna","region_gid":"whosonfirst:region:85681667","region_a":"WI","localadmin":"Wien","localadmin_gid":"whosonfirst:localadmin:1108838101","locality":"Vienna","locality_gid":"whosonfirst:locality:101748073","neighbourhood":"Hofburg","neighbourhood_gid":"whosonfirst:neighbourhood:85898679","continent":"Europe","continent_gid":"whosonfirst:continent:102191581","label":"Oberlandesgericht Wien, Vienna, Austria","addendum":{"osm":{"wheelchair":"yes"}}}},{"type":"Feature","geometry":{"type":"Point","coordinates":[16.434439,48.213508]},"properties":{"id":"way/350584631","gid":"openstreetmap:venue:way/350584631","layer":"venue","source":"openstreetmap","source_id":"way/350584631","name":"Wakeboardlift Wien","confidence":1,"match_type":"exact","accuracy":"point","country":"Austria","country_gid":"whosonfirst:country:85632785","country_a":"AUT","region":"Vienna","region_gid":"whosonfirst:region:85681667","region_a":"WI","localadmin":"Wien","localadmin_gid":"whosonfirst:localadmin:1108838101","neighbourhood":"Praterbrucke","neighbourhood_gid":"whosonfirst:neighbourhood:85898375","continent":"Europe","continent_gid":"whosonfirst:continent:102191581","label":"Wakeboardlift Wien, Wien, WI, Austria","addendum":{"osm":{"operator":"Wakeboardlift Wien","website":"http://www.wakeboardlift.at/"}}},"bbox":[16.4324688,48.2121666,16.4363617,48.2148417]},{"type":"Feature","geometry":{"type":"Point","coordinates":[16.420271,48.270761]},"properties":{"id":"node/3313275952","gid":"openstreetmap:venue:node/3313275952","layer":"venue","source":"openstreetmap","source_id":"node/3313275952","name":"Wien Siemensstraße","confidence":1,"match_type":"exact","accuracy":"point","country":"Austria","country_gid":"whosonfirst:country:85632785","country_a":"AUT","region":"Vienna","region_gid":"whosonfirst:region:85681667","region_a":"WI","localadmin":"Wien","localadmin_gid":"whosonfirst:localadmin:1108838101","locality":"Vienna","locality_gid":"whosonfirst:locality:101748073","neighbourhood":"Neujedlersdorf","neighbourhood_gid":"whosonfirst:neighbourhood:85898343","continent":"Europe","continent_gid":"whosonfirst:continent:102191581","label":"Wien Siemensstraße, Vienna, Austria","addendum":{"osm":{"wheelchair":"yes","operator":"ÖBB-Infrastruktur AG"}}}}],"bbox":[16.336282,48.18501,16.4363617,48.270761]}

And what now?
How can I use result to show user the location (or direction)?! It's posible to show map inside of desktop B4J app with WebView?
And how?

I can not find any example... Sorry, maybe it's stupid question, I'm new in world of B4J with web api... Any suggestion how to move forward will more as usefull...

Tnx, Darko
 

TILogistic

Expert
Licensed User
Longtime User
use:


if you use webview, you can use any map.

OpenStreetMap, MapBox, Marques, etc.
 
Upvote 0

DarkoT

Active Member
Licensed User
Great news from you...
Have you any example how can I open a map and locate position?
I understand what I will get but I don't know how to use results to show results to the users...

Thank you... (you will get a coffe
 
Upvote 0

DarkoT

Active Member
Licensed User
Jap... Thank you...
I just need to writte a simple DESKTOP App, not web app...
But - in any case - I will study suggested material and hope will understand the logic...
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
In whole i see this:
1. Request some API: Input = 2 points, start and finish, the result: the track, points list (that it needs to be got from JSON API result)
2. Open some map
3. Draw the way curve using the points list = numbered markers
4. All the time show user's current position marker, in the background
5. Optionally - the navigation i.e. calculating the azimuth to the next nearest route point from the current user position. And suggesting the moving variant by text or voice...
 
Upvote 0

DarkoT

Active Member
Licensed User
Yes!
I understand the logic, but I don't know how to use results from API to show the map... Will really need some example how to build link and use it with result from API?

When i Create a link - like this - the system will not show the map...
Link:
ShowWebPage.LoadUrl("http://router.project-osrm.org/route/v1/driving/13.388860,52.517037;13.397634,52.529407;13.428555,52.523219?overview=false")

everythink else is logical, I just don't know how to create a link (URL) and show map inside of my desktop app (with webview)...

Tnx...
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
understand the logic now?

Note:
For route optimization there are other factors to consider, such as
the shortest route, traffic status, schedule, etc.
 
Upvote 0

DarkoT

Active Member
Licensed User
understand the logic now?
I'm not sure, but in any case - thank you...

I was expected that will be not so complicated...

My logic was just simple:
1. Ask some open API about coordinates of starting and ending point (user input street and address)
2. Api will return the coordinates (from starting point and ending point)
3. create web link with coordinates, open link inside of my app with given coordinates and
4. in webview will be appears a map with a written road...


I will try to figure out how is posible to use given information (need more time)

Thank you ...
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…