MCPcopy Create free account
hub / github.com/comaps/comaps / OnLocationUpdate

Method OnLocationUpdate

libs/drape_frontend/my_position_controller.cpp:450–570  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

448}
449
450void MyPositionController::OnLocationUpdate(location::GpsInfo const & info, bool isNavigable, double distanceToNextTurn,
451 double speedLimit, ScreenBase const & screen)
452{
453 m2::PointD const oldPos = GetDrawablePosition();
454 double const oldAzimut = GetDrawableAzimut();
455
456 m2::RectD const rect = mercator::MetersToXY(info.m_longitude, info.m_latitude, info.m_horizontalAccuracy);
457 // Use FromLatLon instead of rect.Center() since in case of large info.m_horizontalAccuracy
458 // there is significant difference between the real location and the estimated one.
459 m_position = mercator::FromLatLon(info.m_latitude, info.m_longitude);
460 m_errorRadius = rect.SizeX() * 0.5;
461 m_horizontalAccuracy = info.m_horizontalAccuracy;
462
463 if (distanceToNextTurn >= 0.0 || speedLimit >= 0.0)
464 {
465 double const mercatorPerMeter = m_errorRadius / info.m_horizontalAccuracy;
466 m_autoScale2d =
467 mercatorPerMeter * CalculateAutoZoom(speedLimit, distanceToNextTurn, false /* isPerspectiveAllowed */);
468 m_autoScale3d =
469 mercatorPerMeter * CalculateAutoZoom(speedLimit, distanceToNextTurn, true /* isPerspectiveAllowed */);
470 }
471 else
472 {
473 m_autoScale2d = m_autoScale3d = kUnknownAutoZoom;
474 }
475
476 // Sets direction based on GPS if:
477 // 1. Compass is not available.
478 // 2. Direction must be glued to the route during routing (route-corrected angle is set only in
479 // OnLocationUpdate(): in OnCompassUpdate() the angle always has the original value.
480 // 3. Device is moving faster then pedestrian.
481 bool const isMovingFast = info.HasSpeed() && info.m_speed > kMinSpeedThresholdMps;
482 bool const glueArrowInRouting = isNavigable && m_isArrowGluedInRouting;
483
484 if ((!m_isCompassAvailable || glueArrowInRouting || isMovingFast) && info.HasBearing())
485 {
486 SetDirection(math::DegToRad(info.m_bearing));
487 m_lastGPSBearingTimer.Reset();
488 }
489
490 if (m_isPositionAssigned && (!AlmostCurrentPosition(oldPos) || !AlmostCurrentAzimut(oldAzimut)))
491 {
492 CreateAnim(oldPos, oldAzimut, screen);
493 m_isDirtyViewport = true;
494 }
495
496 // Assume that every new position is fresh enough. We can't make some straightforward filtering here
497 // like comparing system_clock::now().time_since_epoch() and info.m_timestamp, because can't rely
498 // on valid time settings on endpoint device.
499 m_positionIsObsolete = false;
500
501 if (!m_isPositionAssigned)
502 {
503 ChangeMode(m_isInRouting ? m_preferredRoutingMode : m_desiredInitMode, true);
504
505 if (!m_hints.m_isFirstLaunch || !AnimationSystem::Instance().AnimationExists(Animation::Object::MapPlane))
506 {
507 if (m_mode == location::Follow)

Callers 1

AcceptMessageMethod · 0.45

Calls 14

MetersToXYFunction · 0.85
CalculateAutoZoomFunction · 0.85
DegToRadFunction · 0.85
ResetNotificationFunction · 0.85
SizeXMethod · 0.80
HasSpeedMethod · 0.80
HasBearingMethod · 0.80
AnimationExistsMethod · 0.80
PositionChangedMethod · 0.80
GetZoomLevelFunction · 0.70
FromLatLonFunction · 0.50
PositionClass · 0.50

Tested by

no test coverage detected