我正在使用 HERE MAPS SDK PREMIUM V3.18.3 并且我正在尝试使用 routeOptions.truckShippedHazardousGoods = RouteOptions.HazardousGoodType.COMBUSTIBLE 获取卡车路线这给出了一个错误说明:类型不匹配。必需:EnumSet<RouteOptions.HazardousGoodType!> 找到:RouteOptions.HazardousGoodType
val routeOptions = RouteOptions()
routeOptions.setTransportMode(RouteOptions.TransportMode.TRUCK)
routeOptions.setHighwaysAllowed(true)
routeOptions.truckHeight = truckHeightMeters
routeOptions.truckLength = truckLengthMeters
routeOptions.truckWidth = truckWidthMeters
routeOptions.truckLimitedWeight = truckLimitedWeightTon
routeOptions.truckTrailersCount = numberOfTrailers
routeOptions.truckShippedHazardousGoods = Hazmat.COMBUSTABLE
routeOptions.speedProfile
routeOptions.routeType = RouteOptions.Type.FASTEST
routeOptions.routeCount = 1
routeOptions.setTruckTunnelCategory(RouteOptions.TunnelCategory.E)
.setTruckLength(truckLengthMeters)
.setTruckHeight(truckHeightMeters)
.setTruckTrailersCount(numberOfTrailers)
所以我创建了一个枚举类:
enum class Hazmat : EnumSet<RouteOptions.HazardousGoodType!> {
COMBUSTABLE {
override fun iterator(): MutableIterator<RouteOptions.HazardousGoodType> {
COMBUSTABLE
return iterator()
}
override val size: Int
get() = 0
},
CORROSIVE {
override fun iterator(): MutableIterator<RouteOptions.HazardousGoodType> {
CORROSIVE
return iterator()
}
override val size: Int
get() = 1
},
EXPLOSIVE {
override fun iterator(): MutableIterator<RouteOptions.HazardousGoodType> {
EXPLOSIVE
return iterator()
}
override val size: Int
get() = 2
},
FLAMMABLE {
override fun iterator(): MutableIterator<RouteOptions.HazardousGoodType> {
FLAMMABLE
return iterator()
}
override val size: Int
get() = 3
},
GAS {
override fun iterator(): MutableIterator<RouteOptions.HazardousGoodType> {
GAS
return iterator()
}
override val size: Int
get() = 4
},
HARMFUL_TO_WATER {
override fun iterator(): MutableIterator<RouteOptions.HazardousGoodType> {
HARMFUL_TO_WATER
return iterator()
}
override val size: Int
get() = 5
},
ORGANIC {
override fun iterator(): MutableIterator<RouteOptions.HazardousGoodType> {
ORGANIC
return iterator()
}
override val size: Int
get() = 6
},
OTHER {
override fun iterator(): MutableIterator<RouteOptions.HazardousGoodType> {
OTHER
return iterator()}
override val size: Int
get() = 7
},
POISON {
override fun iterator(): MutableIterator<RouteOptions.HazardousGoodType> {
POISON
return iterator()
}
override val size: Int
get() = 8
},
RADIOACTIVE {
override fun iterator(): MutableIterator<RouteOptions.HazardousGoodType> {
RADIOACTIVE
return iterator()
}
override val size: Int
get() = 9
},
POISONOUS_INHALATION {
override fun iterator(): MutableIterator<RouteOptions.HazardousGoodType> {
POISONOUS_INHALATION
return iterator()
}
override val size: Int
get() = 10
}
}
如果我保持 ! 在 EnumSet<RouteOptions.HazardousGoodType!> 我得到错误:意外的令牌。当我将代码更改为
routeOptions.truckShippedHazardousGoods = Hazmat.COMBUSTABLE
它显示: public final enum class Hazmat : EnumSet<RouteOptions.HazardousGoodType> 用于 Hazmat 并获得 COMBUSTABLE 的正确条目和 const。
但就像我说的,当我离开时,我得到了 Unexpected 错误令牌!在 EnumSet<RouteOptions.HazardousGoodType!>
如果我拿!出我得到这个错误:枚举类不能从类继承这个类型有一个构造函数,因此必须在这里初始化
我不确定我错过了什么?我查看了 HERE.com 文档,我发现了这个 API 参考,但它也遗漏了 ! 来自 EnumSet<RouteOptions.HazardousGoodType!> 但该链接也只使用 Enum<RouteOptions.HazardousGoodType> 而不是 EnumSet。我已经尝试过 Enum,但是当发现不匹配类型 Hazmat 并且需要 EnumSet<RouteOptions.HazardousGoodType!> 时它仍然给出错误。有任何想法吗?
编辑!!所以我尝试了这个,它似乎工作正常:
val hazmatCorrosive: EnumSet<RouteOptions.HazardousGoodType> = EnumSet.of(
RouteOptions.HazardousGoodType.CORROSIVE
)
val hazmatExplosive: EnumSet<RouteOptions.HazardousGoodType> = EnumSet.of(
RouteOptions.HazardousGoodType.EXPLOSIVE
)
val hazmatFlammable: EnumSet<RouteOptions.HazardousGoodType> = EnumSet.of(
RouteOptions.HazardousGoodType.FLAMMABLE
)
val hazmatGas: EnumSet<RouteOptions.HazardousGoodType> = EnumSet.of(
RouteOptions.HazardousGoodType.GAS
)
val hazmatHarmfulToWater: EnumSet<RouteOptions.HazardousGoodType> = EnumSet.of(
RouteOptions.HazardousGoodType.HARMFUL_TO_WATER
)
val hazmatOther: EnumSet<RouteOptions.HazardousGoodType> = EnumSet.of(
RouteOptions.HazardousGoodType.OTHER
)
val hazmatOrganic: EnumSet<RouteOptions.HazardousGoodType> = EnumSet.of(
RouteOptions.HazardousGoodType.ORGANIC
)
val hazmatPoison: EnumSet<RouteOptions.HazardousGoodType> = EnumSet.of(
RouteOptions.HazardousGoodType.POISON
)
val hazmatPoisonousInhilation: EnumSet<RouteOptions.HazardousGoodType> = EnumSet.of(
RouteOptions.HazardousGoodType.POISONOUS_INHALATION
)
val hazmatRadioactive: EnumSet<RouteOptions.HazardousGoodType> = EnumSet.of(
RouteOptions.HazardousGoodType.RADIOACTIVE
)
val hazmatCombustable: EnumSet<RouteOptions.HazardousGoodType> = EnumSet.of(
RouteOptions.HazardousGoodType.COMBUSTIBLE
)
MapLoader.getInstance().selectDataGroup(MapPackage.SelectableDataGroup.TruckAttributes)
val coreRouter = CoreRouter()
val routePlan = RoutePlan()
val routeOptions = RouteOptions()
routeOptions.transportMode = RouteOptions.TransportMode.TRUCK
routeOptions.setHighwaysAllowed(true)
routeOptions.truckHeight = truckHeightMeters
routeOptions.truckLength = truckLengthMeters
routeOptions.truckWidth = truckWidthMeters
routeOptions.truckLimitedWeight = truckLimitedWeightTon
routeOptions.truckTrailersCount = numberOfTrailers
if (combustable or corrosive or explosive or flammable or gas or harmfulToWater or other or organic or poisonousInhilation or poison or radioactive) {
try {
routeOptions.truckShippedHazardousGoods = if (combustable) {
hazmatCombustable
} else if (corrosive) {
hazmatCorrosive
} else if (explosive) {
hazmatExplosive
} else if (flammable) {
hazmatFlammable
} else if (gas) {
hazmatGas
} else if (harmfulToWater) {
hazmatHarmfulToWater
} else if (other) {
hazmatOther
} else if (organic) {
hazmatOrganic
} else if (poison) {
hazmatPoison
} else if (poisonousInhilation) {
hazmatPoisonousInhilation
} else if (radioactive) {
hazmatRadioactive
} else return
} catch (e: Exception) {
e.printStackTrace()
}
Toast.makeText(this, "Hazmat routing selected. If you're not currently hauling hazmat, update the vehicle profile.", Toast.LENGTH_LONG).show()
}
routeOptions.speedProfile
routeOptions.isTruckDifficultTurnsAllowed = false
routeOptions.truckRestrictionsMode = RouteOptions.TruckRestrictionsMode.NO_VIOLATIONS
routeOptions.routeType = RouteOptions.Type.FASTEST
routeOptions.routeCount = 1
有一个更好的方法吗?