Thanks for the hints. I increased the code to add the max_speed as a function of the roadType when the maxspeed info is not present for that segment:
public void pointDirectSnap(TrackPoint trackPoint){
GraphHopper graphHopper= MapHandler.getMapHandler().getHopper();
LocationIndex index = graphHopper.getLocationIndex();
QueryResult snap = index.findClosest(trackPoint.getLatitude(), trackPoint.getLongitude(), EdgeFilter.ALL_EDGES);
if (snap.isValid()) {
EdgeIteratorState edge = snap.getClosestEdge();
trackPoint.setRoad_name(edge.getName());
flagEncoder = (CarFlagEncoder) graphHopper.getEncodingManager().getEncoder("car");
IntsRef intsRef = edge.getFlags();
double max_speed = flagEncoder.getDecimalEncodedValue(MaxSpeed.KEY).getDecimal(true, intsRef);
EnumEncodedValue<RoadClass> roadType = flagEncoder.getEnumEncodedValue(RoadClass.KEY, RoadClass.class);
trackPoint.setType(String.valueOf(roadType.getEnum(false, intsRef)));
if ((max_speed != Double.POSITIVE_INFINITY) && (max_speed < 140) && (max_speed > 10)) {
trackPoint.setMax_speed(max_speed);
trackPoint.setMaxSpeedinMap(true);
} else //If max_Speed= Infinity, ie no speed limit has been found in OSM Maps
{
trackPoint.setMaxSpeedinMap(false);
switch (roadType.getEnum(false, intsRef)) {
case MOTORWAY:
trackPoint.setMax_speed(120);
break;
case TRUNK:
case PRIMARY:
case SECONDARY:
case TERTIARY:
trackPoint.setMax_speed(90);
break;
case SERVICE:
case TRACK:
trackPoint.setMax_speed(40);
break;
case RESIDENTIAL:
case BRIDLEWAY:
case STEPS:
case CYCLEWAY:
case PATH:
case LIVING_STREET:
case FOOTWAY:
case PEDESTRIAN:
case PLATFORM:
case CORRIDOR:
trackPoint.setMax_speed(20);
break;
case ROAD:
case UNCLASSIFIED:
case OTHER:
default:
trackPoint.setMax_speed(80);
break;
}
}
}
else { trackPoint.setRoad_name("Road Not found"); }
}
In order to complete the info, how could I get the Municipality of that road/edge? (the city the car is in? place/municipality feature)
Thanks,