Blog
Coordinates Using the iPhone Simulator
12/30/09
One of the small challenges in developing iPhone applications is using the GPS location in the iPhone Simulator. While it’s good to test frequently on the iPhone during development, the Simulator is used most often and it’s difficult to recreate what you are seeing on the iPhone when your iPhone properly determines where you are at, but the Simulator defaults to Apple’s office at 1 Infinite Loop in California.
I’ve gone in from time to time to hardcode results in the simulator to be my current location so that the Simulator will return the same coordinates as the iPhone, but this can be dangerous because you have to remember to take out the hard coded coordinates.
By using the UIDevice class, you can easily determine if you are using the Simulator or not. By determining if you are using the Simulator, you can throw in your test coordinates and not worry about accidentally leaving in test coordinates when you are making a build for users.
The code example below shows a locationManager function to do a onetime retrieval of the position, detect if you are using the Simulator and then set default coordinates:
- (void)locationManager:(CLLocat
ionManager *)manager didUpdateToLocation:(CLLocatio
n *)newLocation fromLocation:(CLLocation *)oldLocation
{
CLLocationCoordinate2D loc = [newLocation coordinate];
NSLog( @"We're at %f, %f\n", loc.latitude, loc.longitude );
[locmanager stopUpdatingLocation];
//get a string that contains what the current device is: iPod, iPod Touch, etc.
NSString* model = [[UIDevice currentDevice] model];
if ( [model compare:@"iPhone Simulator"] == NSOrderedSame )
{
NSLog( @"We're using the simulator so override the coordinates" );
myCoordinate.latitude = 41.9030592;
myCoordinate.longitude = -87.9871786;
}
else
{
myCoordinate.latitude = loc.latitude;
myCoordinate.longitude = loc.longitude;
}
//user made function to update the screen with the results from myCoordinate
[self ShowResults];
}
This mechanism is also good for testing your application in places you’ll never get to. It’s not good practice to only test a location based app in the small range of places you might be doing your development.
Have other ideas? Contact us with them.
- Dave Gruen Senior Vice-President, Consulting Division
More Blog Articles
- How is Your Web Strategy? - 03/05/10
- Patience is The Key to Web Success - 03/05/10
- The Website ROI Factor - 02/28/10
- Live Support Chat Software - 02/26/10
- Automate Your Workforce with iPhone - 02/25/10
- Mobile CRM - 02/23/10
- Wordpress for iPhone - 02/22/10
- Mobile Development - 02/19/10
- Coordinates Using the iPhone Simulator - 12/30/09
- Social Media - 12/24/09
- LINQ Likes Foreign Keys - 11/16/09
- Adding a Flickr Slide Show to Your Website - 10/07/09
- Adding a Twitter Feed to Your Site - 09/22/09
- Making Sure Your Website Is Browser Friendly - 09/11/09
- Adding your Facebook Fan Box to Your Website - 08/13/09
- Whats the big deal about BING? - 07/31/09
- Web Design Radio Interview pt 4 - 06/25/09
- Adding a Start Date and End Date to your WordPress Posts - 06/16/09
- Web Design Radio Interview pt 3 - 05/15/09
- Web Design Radio Interview pt 2 - 05/08/09
- Web Design Radio Interview pt 1 - 05/07/09
- Radio Interview - 05/04/09
- Is it Time to Add a Survey Tool to Your Website? - 04/29/09
- Key Step in Building a Website - 04/16/09
- Google Analytics Now Offers iPhone Tracking on Your Website Analytics. - 04/15/09
- Google Video to Discontinue Upload Service - 04/03/09
- LINQ to Objects - 04/01/09
- Sales in a Down Economy - 03/31/09
- Integrating The Facebook Connect Platform Into Your Website - 03/27/09
- Is it Time to Make Sure Your Website is Formatted for Higher Resolution Monitors? - 03/24/09
- Another Reason Reviewing Google Analytics Data is Important. - 03/20/09
- Client-side Reports Using the Report Viewer - 03/18/09
- Targeting the Right Destination in a Hyperlink - 03/17/09
- Is Your Website Multilingual? Should It Be? - 03/12/09
- How to Use Javascript Effectively Without Hurting Your Web Site Search Engine Optimization - 03/05/09
- Top 7 Myths of Web Development - 03/04/09
- Using LINQ - 03/02/09
- Facebook as a Business Tool - 02/27/09
- Proper Keyword Selection for SEO - 02/24/09
- My brother knows a guy who knows a guy who does websites for $500. - 02/23/09
- Maintaining High Touch in a High Tech World - 02/19/09
- Search Engine Optimization And W3C Compliant Web Pages - 02/18/09
- Reach potential clients through RSS - Part 2 - 02/18/09
- Reach potential clients through RSS - Part 1 - 02/17/09
