⬆️ ⬇️

Under the wing of the plane sings about something

image



If you look closely at the image on the left, it is easy to determine the location of the author.

It is enough to take a compass and an atlas of Russia.

Set the caliper leg in Sasovo and draw a circle with a radius of 103 km.

Then draw another circle (the center is in Sormovo) with a radius of 141 km.

I'll be at the intersection. Achtung! Fire!



I will tell you how I wrote an altimeter application that is interesting for airline travelers. No ads. No money Clean code.



My friend, careless rider, often flies Moscow-Geneva and back



And he asked me to do him a favor. Make an iPhone application that informs you about the current altitude. And also, something informative.

I guessed that the plane looked like my village outside Krasnoyarsk. That is, the Internet is completely absent. I decided to stuff a list of legal airports in the world and lingerie galleries directly into the app. What else to do on board an airplane, if not contemplating the beautiful or the distant?

')

GPS on



Modern GPS-sensor iPhone stores planetary coordinates and altitude above sea level. Accuracy height-measure depends on various factors, but sometimes good enough - less than 6 yards. In this case, you can, by turning on the application, jump from the roof of a skyscraper and watch the height change online . Warning Warning! This can be dangerous for your health️.



Turning on the GPS tracker in the application takes 7 lines

CLLocationManager *locationManager; //      ViewController // Do any additional setup after loading the view, typically from a nib. locationManager = [CLLocationManager new]; [locationManager requestWhenInUseAuthorization]; [locationManager requestAlwaysAuthorization]; locationManager.delegate = self; locationManager.desiredAccuracy = kCLLocationAccuracyBest; [locationManager startUpdatingLocation]; 




After that, two functions appear in your class, in which messages from the GPS sensor are regularly dumped.

One function comes to life when the sensor is working, and the second when the sensor is broken or does not see the satellites.



 - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{ CLLocation *currentLocation = [locations objectAtIndex:0]; NSLog(@"GPS Tracking %f", currentLocation.verticalAccuracy); [playView updateHeight:currentLocation.altitude]; //   } -(void) locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { NSLog(@"GPS Error %@, denied=%d", error.description, error.code==kCLErrorDenied); } 




Do you think everything will work now? Nah



For the application to work, the above was not enough. Nothing came to the didUpdateLocations function. And, in general, she was not called. And the didFailWithError function did not breathe.

It turned out that you need to enable two checkboxes in the settings of the application, (we follow the hand, once) - Targets-> Capabilities-> Background modes->

image

After these magical actions, the application earned, yo-ho-ho!

How you will now process messages is a purely individual matter.



Application design



I decided to show in portrait mode



Well, yes, burgundy point is added to the schedule 1 time per minute. There are 25 such points in total, so old points are forgotten when new ones appear and are not drawn. Is everything simple? Yes, and so lively.



Of course, in landscape mode, the big numbers go off beautifully and the whole session appears.

Added buttons to stop tracking and continue or start snooping again .

These buttons are necessary because the surveillance mode eats the battery (I really did not notice this) and lights up an unpleasant blue background at the top of the screen when the application goes into sleep or inactive mode.



Beautiful graphics



To draw graphs, I applied the following trick.

Started the pictures

image



Overlapped the segments between the points of the graph type UIImageView

And transformed segments according to the law of linear algebra, hallowed her name

 for (int k=0;k<24-1;k++) { UIImageView *p1 = [pointsQ objectAtIndex:k]; UIImageView *p2 = [pointsQ objectAtIndex:k+1]; UIImageView *p = [linesQ objectAtIndex:k]; float x1 = p1.center.x; float x2 = p2.center.x; float y1 = Y0 - (q2[k]-hmin)*dh; float y2 = Y0 - (q2[k+1]-hmin)*dh; float l2 = hypot((x2-x1),(y2-y1)); float cDy = 1.0/l2; float a = -(x2-x1)*2.0/cellDy; float c = -(y2-y1)*cDy; float b = -(y2-y1)*2.0/cellDy; float d = (x2-x1)*cDy; float tx = 0.0; float ty = 0.0; p.alpha = (q1[k]*q1[k+1]) ? 1.0 : 0.0; p.center = CGPointMake(0.5*(x1+x2), 0.5*(y1+y2)); p.transform = CGAffineTransformMake(a, b, c, d, tx, ty); } 




Here p1, p2 are points between which it is necessary to draw a segment p, q1 [x] is an array of flags of the height value (0 is no value), q2 [x] is an array of height values, cellDy is the size of the image in pixels. Y0 is the shift of the graph on height. Pervert, say? Yes, I like such tricks, that I can hide there, I remember the times of mind games.

The last three operators can be replaced by one, but this is homework.



Homework response
  p.transform = (q1[k]*q1[k+1]) ? CGAffineTransformMake(a, b, c, d, 0.5*(x1+x2), 0.5*(y1+y2)) : CGAffineTransformMakeScale(0, 0); 






image

Here is a flight. With a large amount of data, I interpolate elevation values ​​at 40 key points. I checked the work for 36 hours in a row, I think no one will surpass my record.



List of airports



The list of airports should be placed in the application so that it is available at any time, regardless of the availability of the Internet.

Took data on the airfields by the first link from the request free airports list xml

I packed the list into airports.sql file (less than 9000 units), added the file to the project, and when I launch the application, I read and load airports.sql into the Airport structure

 #import <sqlite3.h> #import <Foundation/Foundation.h> @interface Airport : NSObject { } @property (nonatomic) NSInteger db_id; @property (nonatomic) NSString *name; @property (nonatomic) NSString *city; @property (nonatomic) NSString *country; @property (nonatomic) NSString *iata; @property (nonatomic) NSString *icao; @property (nonatomic) double latitude; @property (nonatomic) double longitude; @property (nonatomic) double altitude; @property (nonatomic) int timezone; @property (nonatomic) NSString *dst; @property (nonatomic) NSString *timezone_name; @property (nonatomic, retain) CLLocation* location; @property (nonatomic,readonly) double distanceFromHere; - (id) initWithSQLStatement:(sqlite3_stmt *) selectstmt; - (double) distanceFromLocation:(CLLocation*)location; /* id integer, name text, city text, country text, iata text, icao text, latitude float, longitude float, altitude float, timezone integer, dst text, timezone_name text */    ,    @end 




The calculation of the distance from the current position to any airport is done by Apple long before me

 - (double) distanceFromLocation:(CLLocation*)location { _distanceFromHere = [self.location distanceFromLocation:location]; return _distanceFromHere; } 


Then I add a sort and list the top ten nearest airports (UITableViewController).

I was surprised to find that the nearest airfield is not in Nizhny Novgorod, but in Sasovo, Ryazan Province. Here are the wonders. I was in this Sasovo flight school in 1991. Nicolas D. and I made a Yak-52 simulator on the AT-286. 12 frames per second, assembler, remember vaguely, Pascal, again assembler, cocktail Chassis-Royal .



List of lingerie salons



Initially, I wanted to shove the photos and fake names of virtual courtesans of the largest cities in Europe. You fly, you know, and the list is updated. But I did not dare - suddenly the Review Team is able to replace height, they will ban me for naked boobs. Limited to beautiful linen.

image

Added by the same algorithm as the airfields.

However, the quest turned out, the chip works only at an altitude above 9000 meters.



Butting with shop



image



The application was quickly made (as part of a useless event, 6 applications in 6 weeks ) and was long approved in the store. Very long, almost two months.

The ambush was that the user should be warned with the following phrase



Continued use of GPS running in the background can dramatically decrease battery life


The first time the application slowed down - they said let's fix it.



I beautifully interposed

️Continued use of GPS running in the background can dramatically decrease battery life️




And turned out to be an idiot. These yellow special characters are prohibited.

I had to wait another 10 days, and then another 10 ...

And today approved .



Application Verification



Yes, I had to fly. Not me, of course, oats are expensive today. The problem was clarified. In the chairs at the aisle, the application often does not work. GPS, a scoundrel, does not see satellites.

I was comforted by the fact that there is a (wonderful?) Occasion to meet with a (lovely?) Companion at the window.



At the porthole satellites and companions can be seen wonderfully.

Source: https://habr.com/ru/post/252043/



All Articles