forked from organicmaps/organicmaps
[iOS] add altitude and speed to my location PP
This commit is contained in:
parent
62d96994e0
commit
d3c0180232
6 changed files with 72 additions and 55 deletions
|
@ -36,6 +36,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
@property(nonatomic, readonly) float rawRating;
|
||||
@property(nonatomic, readonly) PlacePageDataSchedule schedule;
|
||||
@property(nonatomic, readonly) PlacePageDataHotelType hotelType;
|
||||
@property(nonatomic, readonly) BOOL isMyPosition;
|
||||
@property(nonatomic, readonly) BOOL hasBanner;
|
||||
@property(nonatomic, readonly) BOOL isPopular;
|
||||
@property(nonatomic, readonly) BOOL isBookingPlace;
|
||||
|
|
|
@ -79,6 +79,7 @@ static PlacePageDataHotelType convertHotelType(std::optional<ftypes::IsHotelChec
|
|||
_pricing = rawData.GetApproximatePricing().empty() ? nil : @(rawData.GetApproximatePricing().c_str());
|
||||
_rawPricing = rawData.GetRawApproximatePricing() ? nil : [[NSNumber alloc] initWithInt: *(rawData.GetRawApproximatePricing())];
|
||||
_rawRating = rawData.GetRatingRawValue();
|
||||
_isMyPosition = rawData.IsMyPosition();
|
||||
_isPopular = rawData.GetPopularity() > 0;
|
||||
_isBookingPlace = rawData.GetSponsoredType() == place_page::SponsoredType::Booking;
|
||||
_schedule = convertOpeningHours(rawData.GetOpeningHours());
|
||||
|
|
|
@ -10,27 +10,6 @@
|
|||
namespace location_helpers
|
||||
{
|
||||
|
||||
static inline NSString * formattedSpeedAndAltitude(CLLocation * location)
|
||||
{
|
||||
if (!location)
|
||||
return nil;
|
||||
NSMutableString * result = [@"" mutableCopy];
|
||||
if (location.altitude)
|
||||
[result appendString:[NSString stringWithFormat:@"%@ %@", @"\xE2\x96\xB2", @(measurement_utils::FormatAltitude(location.altitude).c_str())]];
|
||||
|
||||
// Speed is actual only for just received location
|
||||
if (location.speed > 0. && location.timestamp.timeIntervalSinceNow >= -2.0)
|
||||
{
|
||||
if (result.length)
|
||||
[result appendString:@" "];
|
||||
|
||||
[result appendString:[NSString stringWithFormat:@"%@%@",
|
||||
[MWMLocationManager speedSymbolFor:location.speed],
|
||||
@(measurement_utils::FormatSpeedWithDeviceUnits(location.speed).c_str())]];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline NSString * formattedDistance(double const & meters) {
|
||||
if (meters < 0.)
|
||||
return nil;
|
||||
|
@ -64,17 +43,6 @@ static inline BOOL isMyPositionPendingOrNoPosition()
|
|||
mode == location::EMyPositionMode::NotFollowNoPosition;
|
||||
}
|
||||
|
||||
static inline double headingToNorthRad(CLHeading * heading)
|
||||
{
|
||||
double north = -1.0;
|
||||
if (heading)
|
||||
{
|
||||
north = (heading.trueHeading < 0) ? heading.magneticHeading : heading.trueHeading;
|
||||
north = base::DegToRad(north);
|
||||
}
|
||||
return north;
|
||||
}
|
||||
|
||||
static inline ms::LatLon ToLatLon(m2::PointD const & p) { return mercator::ToLatLon(p); }
|
||||
|
||||
static inline m2::PointD ToMercator(CLLocationCoordinate2D const & l)
|
||||
|
|
|
@ -46,25 +46,33 @@ class PlacePagePreviewViewController: UIViewController {
|
|||
weak var delegate: PlacePagePreviewViewControllerDelegate?
|
||||
|
||||
private var distance: String? = nil
|
||||
private var speedAndAltitude: String? = nil
|
||||
private var heading: CGFloat? = nil
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
let subtitleString = NSMutableAttributedString()
|
||||
if placePagePreviewData.isPopular {
|
||||
subtitleString.append(NSAttributedString(string: L("popular_place"),
|
||||
attributes: [.foregroundColor : UIColor.linkBlue(),
|
||||
.font : UIFont.regular14()]))
|
||||
}
|
||||
if placePagePreviewData.isMyPosition {
|
||||
if let speedAndAltitude = speedAndAltitude {
|
||||
subtitleLabel.text = speedAndAltitude
|
||||
}
|
||||
} else {
|
||||
let subtitleString = NSMutableAttributedString()
|
||||
if placePagePreviewData.isPopular {
|
||||
subtitleString.append(NSAttributedString(string: L("popular_place"),
|
||||
attributes: [.foregroundColor : UIColor.linkBlue(),
|
||||
.font : UIFont.regular14()]))
|
||||
}
|
||||
|
||||
if let subtitle = placePagePreviewData.subtitle ?? placePagePreviewData.coordinates {
|
||||
subtitleString.append(NSAttributedString(string: placePagePreviewData.isPopular ? " • " + subtitle : subtitle,
|
||||
attributes: [.foregroundColor : UIColor.blackSecondaryText(),
|
||||
.font : UIFont.regular14()]))
|
||||
if let subtitle = placePagePreviewData.subtitle ?? placePagePreviewData.coordinates {
|
||||
subtitleString.append(NSAttributedString(string: placePagePreviewData.isPopular ? " • " + subtitle : subtitle,
|
||||
attributes: [.foregroundColor : UIColor.blackSecondaryText(),
|
||||
.font : UIFont.regular14()]))
|
||||
}
|
||||
|
||||
subtitleLabel.attributedText = subtitleString
|
||||
}
|
||||
|
||||
directionView = subtitleDirectionView
|
||||
subtitleLabel.attributedText = subtitleString
|
||||
|
||||
if let address = placePagePreviewData.address {
|
||||
addressLabel.text = address
|
||||
|
@ -173,6 +181,11 @@ class PlacePagePreviewViewController: UIViewController {
|
|||
})
|
||||
}
|
||||
|
||||
func updateSpeedAndAltitude(_ speedAndAltitude: String) {
|
||||
self.speedAndAltitude = speedAndAltitude
|
||||
subtitleLabel?.text = speedAndAltitude
|
||||
}
|
||||
|
||||
@IBAction func onAddReview(_ sender: UIButton) {
|
||||
delegate?.previewDidPressAddReview()
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15705" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="bX8-ZQ-XDA">
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15702" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="bX8-ZQ-XDA">
|
||||
<device id="retina4_7" orientation="portrait" appearance="light"/>
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15706"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15704"/>
|
||||
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
|
||||
<capability name="Stack View standard spacing" minToolsVersion="9.0"/>
|
||||
<capability name="collection view cell content view" minToolsVersion="11.0"/>
|
||||
|
@ -146,6 +146,9 @@
|
|||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
<userDefinedRuntimeAttributes>
|
||||
<userDefinedRuntimeAttribute type="string" keyPath="styleName" value="regular14:blackSecondaryText"/>
|
||||
</userDefinedRuntimeAttributes>
|
||||
</label>
|
||||
<view hidden="YES" contentMode="scaleToFill" horizontalHuggingPriority="1000" horizontalCompressionResistancePriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="jaa-Yj-XQR" customClass="DirectionView" customModule="maps_me" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="0.0" width="70" height="50"/>
|
||||
|
|
|
@ -1,4 +1,17 @@
|
|||
class PlacePageCommonLayout: NSObject, IPlacePageLayout {
|
||||
private lazy var distanceFormatter: MKDistanceFormatter = {
|
||||
let formatter = MKDistanceFormatter()
|
||||
formatter.unitStyle = .abbreviated
|
||||
formatter.units = Settings.measurementUnits() == .imperial ? .imperial : .metric
|
||||
return formatter
|
||||
}()
|
||||
|
||||
private lazy var unitsFormatter: MeasurementFormatter = {
|
||||
let formatter = MeasurementFormatter()
|
||||
formatter.unitOptions = [.providedUnit]
|
||||
return formatter
|
||||
}()
|
||||
|
||||
private var placePageData: PlacePageData
|
||||
private var interactor: PlacePageInteractor
|
||||
private let storyboard: UIStoryboard
|
||||
|
@ -212,6 +225,7 @@ class PlacePageCommonLayout: NSObject, IPlacePageLayout {
|
|||
MWMLocationManager.add(observer: self)
|
||||
if let lastLocation = MWMLocationManager.lastLocation() {
|
||||
onLocationUpdate(lastLocation)
|
||||
self.lastLocation = lastLocation
|
||||
}
|
||||
if let lastHeading = MWMLocationManager.lastHeading() {
|
||||
onHeadingUpdate(lastHeading)
|
||||
|
@ -346,19 +360,36 @@ extension PlacePageCommonLayout {
|
|||
|
||||
extension PlacePageCommonLayout: MWMLocationObserver {
|
||||
func onHeadingUpdate(_ heading: CLHeading) {
|
||||
updateHeading(heading.trueHeading)
|
||||
if !placePageData.isMyPosition {
|
||||
updateHeading(heading.trueHeading)
|
||||
}
|
||||
}
|
||||
|
||||
func onLocationUpdate(_ location: CLLocation) {
|
||||
let ppLocation = CLLocation(latitude: placePageData.locationCoordinate.latitude,
|
||||
longitude: placePageData.locationCoordinate.longitude)
|
||||
let distance = location.distance(from: ppLocation)
|
||||
let distanceFormatter = MKDistanceFormatter()
|
||||
distanceFormatter.unitStyle = .abbreviated
|
||||
let formattedDistance = distanceFormatter.string(fromDistance: distance)
|
||||
previewViewController.updateDistance(formattedDistance)
|
||||
lastLocation = location
|
||||
updateHeading(location.course)
|
||||
if placePageData.isMyPosition {
|
||||
let imperial = Settings.measurementUnits() == .imperial
|
||||
let alt = imperial ? location.altitude / 0.3048 : location.altitude
|
||||
let altMeasurement = Measurement(value: alt.rounded(), unit: imperial ? UnitLength.feet : UnitLength.meters)
|
||||
let altString = "▲ \(unitsFormatter.string(from: altMeasurement))"
|
||||
|
||||
if location.speed > 0 && location.timestamp.timeIntervalSinceNow >= -2 {
|
||||
let speed = imperial ? location.speed * 2.237 : location.speed * 3.6
|
||||
let speedMeasurement = Measurement(value: speed.rounded(), unit: imperial ? UnitSpeed.milesPerHour: UnitSpeed.kilometersPerHour)
|
||||
let speedString = "\(MWMLocationManager.speedSymbolFor(location.speed))\(unitsFormatter.string(from: speedMeasurement))"
|
||||
previewViewController.updateSpeedAndAltitude("\(altString) \(speedString)")
|
||||
} else {
|
||||
previewViewController.updateSpeedAndAltitude(altString)
|
||||
}
|
||||
} else {
|
||||
let ppLocation = CLLocation(latitude: placePageData.locationCoordinate.latitude,
|
||||
longitude: placePageData.locationCoordinate.longitude)
|
||||
let distance = location.distance(from: ppLocation)
|
||||
let formattedDistance = distanceFormatter.string(fromDistance: distance)
|
||||
previewViewController.updateDistance(formattedDistance)
|
||||
|
||||
lastLocation = location
|
||||
updateHeading(location.course)
|
||||
}
|
||||
}
|
||||
|
||||
func onLocationError(_ locationError: MWMLocationStatus) {
|
||||
|
|
Loading…
Add table
Reference in a new issue