Home > Enterprise >  The method getDistanceByRoute(double, double, double, double) is undefined for the type Car Anylogic
The method getDistanceByRoute(double, double, double, double) is undefined for the type Car Anylogic

Time:03-02

i'm quite new in Anylogic and i'm working on a model where some cars of a population travell from a point A to a point B using a GIS route that I have created in the GIS map.

I need to use the function getDistanceByRoute to make some calculations using latitude and longitude but it doesn't work and this error is given:

Description: The method getDistanceByRoute(double, double, double, double) is undefined for the type Car. Location: dinamic3/Car/moving_to_CS - State

I' can't figure out how to fix the problem, i tried the function getDistanceGIS and it worked but i need to use getDistanceByRoute which is more precise with the distance measure.

    @AnyLogicCustomProposalPriority(type = AnyLogicCustomProposalPriority.Type.STATIC_ELEMENT)
  public static final statechart_state at_Milano = statechart_state.at_Milano;
  @AnyLogicCustomProposalPriority(type = AnyLogicCustomProposalPriority.Type.STATIC_ELEMENT)
  public static final statechart_state moving_to_Cortina = statechart_state.moving_to_Cortina;
  @AnyLogicCustomProposalPriority(type = AnyLogicCustomProposalPriority.Type.STATIC_ELEMENT)
  public static final statechart_state moving_to_CS = statechart_state.moving_to_CS;
  @AnyLogicCustomProposalPriority(type = AnyLogicCustomProposalPriority.Type.STATIC_ELEMENT)
  public static final statechart_state at_CS = statechart_state.at_CS;
  @AnyLogicCustomProposalPriority(type = AnyLogicCustomProposalPriority.Type.STATIC_ELEMENT)
  public static final statechart_state state5 = statechart_state.state5;
  @AnyLogicCustomProposalPriority(type = AnyLogicCustomProposalPriority.Type.STATIC_ELEMENT)
  public static final statechart_state at_Cortina = statechart_state.at_Cortina;
  @AnyLogicCustomProposalPriority(type = AnyLogicCustomProposalPriority.Type.STATIC_ELEMENT)
  public static final statechart_state state4 = statechart_state.state4;
  @AnyLogicCustomProposalPriority(type = AnyLogicCustomProposalPriority.Type.STATIC_ELEMENT)
  public static final statechart_state finalState = statechart_state.finalState;


  @AnyLogicInternalCodegenAPI
  private void enterState( statechart_state self, boolean _destination ) {
    switch( self ) {
      case at_Milano:
        logToDBEnterState(statechart, self);
        // (Simple state (not composite))
        statechart.setActiveState_xjal( at_Milano );
        transition2.start();
        return;
      case moving_to_Cortina:
        logToDBEnterState(statechart, self);
        // (Composite state)
        {
moveTo(main.cortina);
consumption_switch=1;
charging_switch=0;
time=time();
 
;}
        transition3.start();
        transition5.start();
        if ( _destination ) {
           enterState( state4, true );
        }
        return;
      case moving_to_CS:
        logToDBEnterState(statechart, self);
        // (Composite state)
        {
double a;
double b;
double c;
double d;

a=main.charging_stations.get(k 1).lat_cs;
b=main.charging_stations.get(k 1).lon_cs;

c=main.charging_stations.get(k).lat_cs;
d=main.charging_stations.get(k).lon_cs;
 

x=(getDistanceByRoute(lat_1,lon_1,a,b)*0.001);

CodePudding user response:

For this function to work, you need to reference the map to which you want it to apply:

map.getDistanceByRoute(double, double, double, double);

So make sure to add the "map." to your code, if this is the name of your map object.

  • Related