Set trace from external source

PTV's mobile solution based on off-line maps - standard application and SDK
Post Reply
MiKu_MichDem
Posts: 3
Joined: Wed Mar 17, 2021 1:05 pm

Set trace from external source

Post by MiKu_MichDem »

We have a specific case - a C# client that saves a route on an internal Java server which then should be displayed on an Android device.

I have issues with doing so on Android as each method for displaying trace requires a child class of a NativeObject at some point. Objects of this class are effectively immutable from Java so I cannot use them.

For example - this is the code I use for :

Code: Select all

        val points = SVPWayPointArray(points.size)
        points.forEachIndexed { index, pointStr ->
            // gathering x and y from pointStr
            val position = GeoPosition(x, y).toPosition()
            val point = SVPWayPoint(WayPoint(position))
            points.set(index, point)
        }

        NavigationSDK.createRouteFromSVPPoints(points.size(), points, 0x000000FF, 0x000000FF)
The code above fails on points.set(index, point). Other approaches that I've found also fail on any sort of manipulation of NativeObject instances.

How then would it be possible to set a trace on a map from already existing trace?
User avatar
Bernd Welter
Site Admin
Posts: 2695
Joined: Mon Apr 14, 2014 10:28 am
Contact:

Re: Set trace from external source

Post by Bernd Welter »

Hello Michal,

I forwarded the topic to Sebastian (Product Management) because I can't answer it by myself.

Best regards,

Bernd
Bernd Welter
Technical Partner Manager Developer Components
PTV Logistics - Germany

Bernd at... The Forum,LinkedIn, Youtube, StackOverflow
I like the smell of PTV Developer in the morning... :twisted:
SebastianSchlichting
Posts: 18
Joined: Tue May 28, 2019 10:45 am

Re: Set trace from external source

Post by SebastianSchlichting »

Actually we can only support java code and native (C++). With C# we don't have any experience and can't support you there.

Here is the example code for Java which extracts the way points from the JSON and creates a WayPointArray.

The corresponding paragraph in the tutorial can be found here: http://navigator.ptvgroup.com/DE/sdk/tu ... ata-format

Code: Select all

JSONArray array = new JSONArray(content);
for (int i = 0; i < array.length(); ++i) {
    JSONObject point = array.getJSONObject(i);
    if (point.getString("type").toUpperCase().equals("SVP")) {
        JSONArray points = point.getJSONArray("points");
        SVPWayPointArray wps = new SVPWayPointArray(points.length());
        for (int j = 0; j < points.length(); ++j) {
            wps.set(j, toSVP(points.getJSONObject(j)) );
        }
    }
 
}
Do you only want to draw a trace, or do you want a trace with a route?

If you want only a trace you have to look into the code of tutorial 10. In the MainActivity there is a method addCircleAroundCurrentPosition. Here you will find an example how to draw a trace only.
MiKu_MichDem
Posts: 3
Joined: Wed Mar 17, 2021 1:05 pm

Re: Set trace from external source

Post by MiKu_MichDem »

Our application is written mostly in Kotlin which is has full interoperability with Java. It's functionally the same as it's compiled into the same code.

I've noticed that in Kotlin I get the following error:

Code: Select all

.lang.IllegalAccessError: Illegal class access: 'pl.softprojekt.fp4mtransport.gui.pages.myOrders.MyOrdersRoutePreview' attempting to access 'com.ptvag.navigation.sdk.NativeObject' (declaration of 'pl.softprojekt.fp4mtransport.gui.pages.myOrders.MyOrdersRoutePreview' appears in /data/app/pl.softprojekt.fp4mtransport-3C8qHB4JPgOa_2czl2fDZw==/base.apk!classes2.dex)
Either way. In pure Java code the SVPWayPointArray is sucesfully created, however it fails on method createRouteFromSVPPoints.

This is how the method is called:

Code: Select all

NavigationSDK.createRouteFromSVPPoints(wayPointArray.size(), wayPointArray, 0x000000FF, 0x000000FF);
And this is the exception it produces:

Code: Select all

java.lang.UnsatisfiedLinkError: No implementation found for void com.ptvag.navigation.sdk.NavigationSDK.createRouteFromSVPPointsJNI(int, long, long, long) (tried Java_com_ptvag_navigation_sdk_NavigationSDK_createRouteFromSVPPointsJNI and Java_com_ptvag_navigation_sdk_NavigationSDK_createRouteFromSVPPointsJNI__IJJJ)
        at com.ptvag.navigation.sdk.NavigationSDK.createRouteFromSVPPointsJNI(Native Method)
        at com.ptvag.navigation.sdk.NavigationSDK.createRouteFromSVPPoints(NavigationSDK.java:436)
        at pl.softprojekt.fp4mtransport.gui.pages.myOrders.Tracer.draw(Tracer.java:25)
        at pl.softprojekt.fp4mtransport.gui.pages.myOrders.MyOrdersRoutePreview.decodePointCollection(MyOrdersRoutePreview.kt:141)
        at pl.softprojekt.fp4mtransport.gui.pages.myOrders.MyOrdersRoutePreview.onViewCreated(MyOrdersRoutePreview.kt:70)
        at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:332)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1187)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1356)
        at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1434)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1497)
        at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:447)
        at androidx.fragment.app.FragmentManager.executeOps(FragmentManager.java:2169)
        at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1992)
        at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1947)
        at androidx.fragment.app.FragmentManager.execSingleAction(FragmentManager.java:1818)
        at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:303)
        at androidx.fragment.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:270)
        at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1244)
        at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1092)
        at androidx.viewpager.widget.ViewPager.onMeasure(ViewPager.java:1622)
        at android.view.View.measure(View.java:25218)
        at androidx.constraintlayout.widget.ConstraintLayout$Measurer.measure(ConstraintLayout.java:792)
        at androidx.constraintlayout.solver.widgets.ConstraintWidgetContainer.measure(ConstraintWidgetContainer.java:583)
        at androidx.constraintlayout.solver.widgets.analyzer.Direct.verticalSolvingPass(Direct.java:355)
        at androidx.constraintlayout.solver.widgets.analyzer.Direct.solveVerticalMatchConstraint(Direct.java:636)
        at androidx.constraintlayout.solver.widgets.analyzer.Direct.verticalSolvingPass(Direct.java:407)
        at androidx.constraintlayout.solver.widgets.analyzer.Direct.verticalSolvingPass(Direct.java:446)
        at androidx.constraintlayout.solver.widgets.analyzer.Direct.solvingPass(Direct.java:178)
        at androidx.constraintlayout.solver.widgets.ConstraintWidgetContainer.layout(ConstraintWidgetContainer.java:642)
        at androidx.constraintlayout.solver.widgets.analyzer.BasicMeasure.solveLinearSystem(BasicMeasure.java:159)
        at androidx.constraintlayout.solver.widgets.analyzer.BasicMeasure.solverMeasure(BasicMeasure.java:290)
        at androidx.constraintlayout.solver.widgets.ConstraintWidgetContainer.measure(ConstraintWidgetContainer.java:119)
        at androidx.constraintlayout.widget.ConstraintLayout.resolveSystem(ConstraintLayout.java:1578)
        at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1690)
        at android.view.View.measure(View.java:25218)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6937)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
        at android.view.View.measure(View.java:25218)
        at androidx.constraintlayout.widget.ConstraintLayout$Measurer.measure(ConstraintLayout.java:792)
        at androidx.constraintlayout.solver.widgets.ConstraintWidgetContainer.measure(ConstraintWidgetContainer.java:583)
SebastianSchlichting
Posts: 18
Joined: Tue May 28, 2019 10:45 am

Re: Set trace from external source

Post by SebastianSchlichting »

Hi,

could you please switch from using createRouteFromSVPPoints to the following:

Code: Select all

    try {
        Tour tour = new Tour(new WayPoint(937168,6270162));
        SVPWayPointArray ar = new SVPWayPointArray(2);
        SVPWayPoint p1 = new SVPWayPoint(934313,6268779,-1);
        SVPWayPoint p2 = new SVPWayPoint(933440,6268782,-1);
        ar.set(0, p1);
        ar.set(1, p2);
        tour.addSVPs(ar);
        CalculateTourResult result = NavigationSDK.calculateTour(tour, calcRouteObserver);
    } catch (NavigationException e) {
        e.printStackTrace();
    }

The functionality which you are using is an error in the API docs, createRouteFromSVPPoints is deprecated. We will fix it in newer version.
Post Reply