CLLocation Testing Category For Major Cities : Rex St John
Sometimes you need to fake locations within your application and the iOS simulator doesn’t come with built in preselected cities and regions.
Tags
- ios
Originally published at rexstjohn.com on April 22, 2013. Recovered from the Internet Archive.
Sometimes you need to fake locations within your application and the iOS simulator doesn’t come with built in preselected cities and regions.
I created this category helper to all my to manually set a location in a major city using the lat / lon coordinates. It is easy enough to add more cities by looking up their lat / lon, but this is a good start.
#import
@interface CLLocation (Testing)
+(CLLocation*)locationInSeattle;
+(CLLocation*)locationInNewYork;
+(CLLocation*)locationInSanFransisco;
+(CLLocation*)locationInBoston;
+(CLLocation*)locationInMiami;
+(CLLocation*)locationInLondon;
@end
#import "CLLocation+Testing.h"
@implementation CLLocation (Testing)
+(CLLocation*)locationInSeattle{
CLLocationDegrees lat = 47.6097;
CLLocationDegrees lon = -122.3331;
CLLocation *someLocation = [[CLLocation alloc] initWithLatitude:lat longitude:lon];
return someLocation;
}
+(CLLocation*)locationInNewYork{
CLLocationDegrees lat = 40.7142;
CLLocationDegrees lon = -74.0064;
CLLocation *someLocation = [[CLLocation alloc] initWithLatitude:lat longitude:lon];
return someLocation;
}
+(CLLocation*)locationInSanFransisco{
CLLocationDegrees lat = 37.7750;
CLLocationDegrees lon = -122.4183;
CLLocation *someLocation = [[CLLocation alloc] initWithLatitude:lat longitude:lon];
return someLocation;
}
+(CLLocation*)locationInBoston{
CLLocationDegrees lat = 42.3583;
CLLocationDegrees lon = -71.0603;
CLLocation *someLocation = [[CLLocation alloc] initWithLatitude:lat longitude:lon];
return someLocation;
}
+(CLLocation*)locationInMiami{
CLLocationDegrees lat = 25.4716;
CLLocationDegrees lon = -80.1327;
CLLocation *someLocation = [[CLLocation alloc] initWithLatitude:lat longitude:lon];
return someLocation;
}
+(CLLocation*)locationInLondon{
CLLocationDegrees lat = 51.5171;
CLLocationDegrees lon = -0.1062;
CLLocation *someLocation = [[CLLocation alloc] initWithLatitude:lat longitude:lon];
return someLocation;
}
@end