Skip to content

Commit

Permalink
Merge pull request #3917 from osmandapp/show_distance_next_turn_carpl…
Browse files Browse the repository at this point in the history
…ay_part2

fix instructionVariants
  • Loading branch information
alex-osm authored Aug 13, 2024
2 parents 44c21ca + 1edd8ac commit 72e8d63
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
35 changes: 31 additions & 4 deletions Sources/CarPlay/OACarPlayDashboardInterfaceController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#import "OATurnDrawable.h"
#import "OATurnDrawable+cpp.h"
#import "OAMapButtonsHelper.h"
#import "OACurrentStreetName.h"
#import "OsmAnd_Maps-Swift.h"

#define unitsKm OALocalizedString(@"km")
Expand Down Expand Up @@ -574,17 +575,43 @@ - (CPManeuver *)createTurnManeuver:(CPTravelEstimates *)estimates directionInfo:
maneuver.symbolImage = [turnDrawable toUIImage];
maneuver.initialTravelEstimates = estimates;
maneuver.userInfo = @{ @"imminent" : @(directionInfo.imminent) };
NSString *streetName = directionInfo.directionInfo.streetName;
NSString *streetName = [self defineStreetName:directionInfo];

if (streetName)
{
NSString *distanceString = [OAOsmAndFormatter getFormattedDistance:directionInfo.distanceTo withParams:[OsmAndFormatterParams useLowerBounds]];
NSString *instruction = [NSString stringWithFormat:@"%@, %@", distanceString, streetName];
maneuver.instructionVariants = @[instruction];
if (estimates) {
maneuver.instructionVariants = @[streetName];
}
else
{
NSString *distanceString = [OAOsmAndFormatter getFormattedDistance:directionInfo.distanceTo withParams:[OsmAndFormatterParams useLowerBounds]];
NSString *instruction = [NSString stringWithFormat:@"%@, %@", distanceString, streetName];
maneuver.instructionVariants = @[instruction];
}
}

return maneuver;
}

- (nullable NSString *)defineStreetName:(nullable OANextDirectionInfo *)nextDirInfo {
if (nextDirInfo)
{
OACurrentStreetName *currentStreetName = [_routingHelper getCurrentName:nextDirInfo];
NSString *streetName = currentStreetName.text;

if (streetName.length > 0)
{
NSString *exitRef = currentStreetName.exitRef;
if (exitRef.length == 0) {
return streetName;
} else {
return [NSString stringWithFormat:OALocalizedString(@"ltr_or_rtl_combine_via_comma"), exitRef, streetName];
}
}
}
return nil;
}

// MARK: Location updates

- (void) onLocationUpdate
Expand Down
3 changes: 1 addition & 2 deletions Sources/Controllers/Map/Widgets/OACurrentStreetName.mm
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ + (NSString *) getRouteSegmentStreetName:(std::shared_ptr<RouteSegmentResult> &)
+ (OACurrentStreetName *) getCurrentName:(OANextDirectionInfo *)n
{
OARoutingHelper *routingHelper = OARoutingHelper.sharedInstance;
OAVoiceRouter *voiceRouter = routingHelper.getVoiceRouter;
OACurrentStreetName *streetName = [[OACurrentStreetName alloc] init];
CLLocation *l = routingHelper.getLastFixedLocation;
OAAnnounceTimeDistances *adt = [[routingHelper getVoiceRouter] getAnnounceTimeDistances];
Expand All @@ -47,7 +46,7 @@ + (OACurrentStreetName *) getCurrentName:(OANextDirectionInfo *)n
if (l && l.speed >=0)
speed = l.speed;
// 1. turn is imminent
if (n.distanceTo > 0 && n.directionInfo && !n.directionInfo.turnType->isSkipToSpeak() &&
if (n.distanceTo > 0 && n.directionInfo && !n.directionInfo.turnType->isSkipToSpeak() &&
[adt isTurnStateActive:[adt getSpeed:l] dist:n.distanceTo * 1.3 turnType:kStatePrepareTurn])
{
NSString *nm = n.directionInfo.streetName;
Expand Down

0 comments on commit 72e8d63

Please sign in to comment.