Archive for the 'Other' Category

Calculating angle between two GPS positions

Easy way to determine bearing/angle between two locations:
Source: Stackoverflow.com

----- CLLocation+Bearing.h

#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>


@interface CLLocation (Bearing)

-(double) bearingToLocation:(CLLocation *) destinationLocation;
-(NSString *) compassOrdinalToLocation:(CLLocation *) nwEndPoint;

@end
---------CLLocation+Bearing.m

#import "CLLocation+Bearing.h"

double DegreesToRadians(double degrees) {return degrees * M_PI / 180;};
double RadiansToDegrees(double radians) {return radians * 180/M_PI;};


@implementation CLLocation (Bearing)

-(double) bearingToLocation:(CLLocation *) destinationLocation {

 double lat1 = DegreesToRadians(self.coordinate.latitude);
 double lon1 = DegreesToRadians(self.coordinate.longitude);

 double lat2 = DegreesToRadians(destinationLocation.coordinate.latitude);
 double lon2 = DegreesToRadians(destinationLocation.coordinate.longitude);

 double dLon = lon2 - lon1;

 double y = sin(dLon) * cos(lat2);
 double x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(dLon);
 double radiansBearing = atan2(y, x);

 return RadiansToDegrees(radiansBearing);
}

Faster Singleton method in Java

The fastest Singleton design pattern implementation by Bill Pugh:

public class Singleton
{
protected Singleton()
{
// ...
}

private static class SingletonHolder
{
private final static Singleton INSTANCE = new Singleton();
}

public static Singleton getInstance()
{
return SingletonHolder.INSTANCE;
}
}

Getting music off/backup iPod on Mac

The iPod manager tool, iTunes allows only to copy your music TO the iPod. However if you would like to get the music off (e.g. migrating to another MP3 player) or simply want to backup it’s storage, you can use the following FREE apps:
DeTune (Recommended)
iPodDisk

For more information: http://www.metaphoriclabs.com/articles/5-ways-to-copy-music-off-your-ipod-windows-mac-os-x/