forked from organicmaps/organicmaps
Use Framework::GetDistanceAndAzimut everywhere.
This commit is contained in:
parent
8da71af0d9
commit
de85bf8cc4
5 changed files with 55 additions and 33 deletions
|
@ -217,7 +217,14 @@ Java_com_mapswithme_maps_SearchActivity_nativeGetResult(
|
|||
string distance;
|
||||
double azimut = -1.0;
|
||||
if (mode >= 2)
|
||||
g_framework->NativeFramework()->GetDistanceAndAzimut(*res, lat, lon, north, distance, azimut);
|
||||
{
|
||||
if (!g_framework->NativeFramework()->GetDistanceAndAzimut(
|
||||
res->GetFeatureCenter(), lat, lon, north, distance, azimut))
|
||||
{
|
||||
// do not show the arrow for far away features
|
||||
azimut = -1.0;
|
||||
}
|
||||
}
|
||||
|
||||
return env->NewObject(klass, methodID,
|
||||
jni::ToJavaString(env, res->GetString()),
|
||||
|
|
|
@ -54,7 +54,8 @@
|
|||
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
BookmarkCategory * cat = GetFramework().GetBmCategory(m_categoryIndex);
|
||||
Framework & fr = GetFramework();
|
||||
BookmarkCategory * cat = fr.GetBmCategory(m_categoryIndex);
|
||||
if (!cat)
|
||||
return nil;
|
||||
|
||||
|
@ -136,27 +137,30 @@
|
|||
cell.accessoryView = compass;
|
||||
}
|
||||
|
||||
double lat, lon, northR;
|
||||
// Get current position and compass "north" direction
|
||||
double azimut = -1.0;
|
||||
double lat, lon;
|
||||
|
||||
if ([m_locationManager getLat:lat Lon:lon])
|
||||
{
|
||||
m2::PointD const center = bm->GetOrg();
|
||||
double const metres = ms::DistanceOnEarth(lat, lon, MercatorBounds::YToLat(center.y), MercatorBounds::XToLon(center.x));
|
||||
cell.detailTextLabel.text = [LocationManager formatDistance:metres];
|
||||
double north = -1.0;
|
||||
[m_locationManager getNorthRad:north];
|
||||
|
||||
if ([m_locationManager getNorthRad:northR])
|
||||
{
|
||||
compass.angle = ang::AngleTo(m2::PointD(MercatorBounds::LonToX(lon),
|
||||
MercatorBounds::LatToY(lat)), center) + northR;
|
||||
compass.showArrow = YES;
|
||||
}
|
||||
else
|
||||
compass.showArrow = NO;
|
||||
string distance;
|
||||
fr.GetDistanceAndAzimut(bm->GetOrg(), lat, lon, north, distance, azimut);
|
||||
|
||||
cell.detailTextLabel.text = [NSString stringWithUTF8String:distance.c_str()];
|
||||
}
|
||||
else
|
||||
{
|
||||
compass.showArrow = NO;
|
||||
cell.detailTextLabel.text = nil;
|
||||
|
||||
if (azimut >= 0.0)
|
||||
{
|
||||
compass.angle = azimut;
|
||||
compass.showArrow = YES;
|
||||
}
|
||||
else
|
||||
compass.showArrow = NO;
|
||||
}
|
||||
}
|
||||
return cell;
|
||||
|
|
|
@ -356,18 +356,25 @@ static void OnSearchResultCallback(search::Results const & res)
|
|||
|
||||
// Get current position and compass "north" direction
|
||||
double azimut = -1.0;
|
||||
string distance;
|
||||
|
||||
double lat, lon;
|
||||
|
||||
if ([m_locationManager getLat:lat Lon:lon])
|
||||
{
|
||||
double north = -1.0;
|
||||
[m_locationManager getNorthRad:north];
|
||||
m_framework->GetDistanceAndAzimut(r, lat, lon, north, distance, azimut);
|
||||
}
|
||||
|
||||
// Assign even empty string if no position found
|
||||
cell.featureDistance.text = [NSString stringWithUTF8String:distance.c_str()];
|
||||
string distance;
|
||||
if (!m_framework->GetDistanceAndAzimut(r.GetFeatureCenter(),
|
||||
lat, lon, north, distance, azimut))
|
||||
{
|
||||
// do not draw arrow for far away features
|
||||
azimut = -1.0;
|
||||
}
|
||||
|
||||
cell.featureDistance.text = [NSString stringWithUTF8String:distance.c_str()];
|
||||
}
|
||||
else
|
||||
cell.featureDistance.text = nil;
|
||||
|
||||
// Show flags only if it has one and no azimut to feature
|
||||
char const * flag = r.GetRegionFlag();
|
||||
|
|
|
@ -1207,7 +1207,7 @@ void Framework::ShowSearchResult(search::Result const & res)
|
|||
#endif
|
||||
}
|
||||
|
||||
void Framework::GetDistanceAndAzimut(search::Result const & res,
|
||||
bool Framework::GetDistanceAndAzimut(m2::PointD const & point,
|
||||
double lat, double lon, double north,
|
||||
string & distance, double & azimut)
|
||||
{
|
||||
|
@ -1217,20 +1217,17 @@ void Framework::GetDistanceAndAzimut(search::Result const & res,
|
|||
m_fixedPos.GetNorth(north);
|
||||
#endif
|
||||
|
||||
m2::PointD const center = res.GetFeatureCenter();
|
||||
|
||||
double const d = ms::DistanceOnEarth(lat, lon,
|
||||
MercatorBounds::YToLat(center.y),
|
||||
MercatorBounds::XToLon(center.x));
|
||||
MercatorBounds::YToLat(point.y),
|
||||
MercatorBounds::XToLon(point.x));
|
||||
|
||||
CHECK ( MeasurementUtils::FormatDistance(d, distance), () );
|
||||
|
||||
// Do not show direction arrow for features that are too far than 25 km.
|
||||
if (north >= 0.0 && d < 25000.0)
|
||||
if (north >= 0.0)
|
||||
{
|
||||
azimut = ang::AngleTo(m2::PointD(MercatorBounds::LonToX(lon),
|
||||
MercatorBounds::LatToY(lat)),
|
||||
center) + north;
|
||||
point) + north;
|
||||
|
||||
double const pi2 = 2.0*math::pi;
|
||||
if (azimut < 0.0)
|
||||
|
@ -1238,6 +1235,9 @@ void Framework::GetDistanceAndAzimut(search::Result const & res,
|
|||
else if (azimut > pi2)
|
||||
azimut -= pi2;
|
||||
}
|
||||
|
||||
// This constant and return value is using for arrow/flag choice.
|
||||
return (d < 25000.0);
|
||||
}
|
||||
|
||||
void Framework::SetRenderPolicy(RenderPolicy * renderPolicy)
|
||||
|
|
|
@ -256,9 +256,13 @@ public:
|
|||
bool GetCurrentPosition(double & lat, double & lon) const;
|
||||
void ShowSearchResult(search::Result const & res);
|
||||
|
||||
/// Calculate distance and direction to search result for the given position.
|
||||
/// @param[out] distance Formatted distance string;
|
||||
void GetDistanceAndAzimut(search::Result const & res,
|
||||
/// Calculate distance and direction to POI for the given position.
|
||||
/// @param[in] point POI's position;
|
||||
/// @param[in] lat, lon, north Current position and heading from north;
|
||||
/// @param[out] distance Formatted distance string;
|
||||
/// @param[out] azimut Azimut to point from (lat, lon);
|
||||
/// @return true If the POI is near the current position (distance < 25 km);
|
||||
bool GetDistanceAndAzimut(m2::PointD const & point,
|
||||
double lat, double lon, double north,
|
||||
string & distance, double & azimut);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue