How can I set the location (as it\'s picked up in CoreLocation services) in the iPhone Simulator?
问题:
回答1:
As of iOS 5, the simulator has a configurable location.
Under the Debug menu, the last entry is \"Location\"; this gives you a sub menu with:
- None
- Custom Location
- Apple Stores
- Apple
- City Bicycle Ride
- City Run
- Freeway Drive
Custom Location lets you enter a Lat/Long value. Bicycle ride, City Run, and Freeway Drive are simulation of a moving location (in Cupertino, of course).
Of course, this does nothing to help with debugging for iOS 4 (or earlier); but it\'s a definite improvement!
回答2:
- Run project in iPhone Simulator
Create in TextEdit file following file, call it MyOffice for example. Make extension as .gpx
<?xml version=\"1.0\"?> <gpx version=\"1.0\" creator=\"MyName\"> <wpt lat=\"53.936166\" lon=\"27.565370\"> <name>MyOffice</name> </wpt> </gpx>
Select in Xcode at the Simulate area
Add GPX File to Project...
- Add created file from menu to project.
- Now you can see your location in Simulate area:
回答3:
In my delegate callback, I check to see if I\'m running in a simulator (#if TARGET_ IPHONE_SIMULATOR
) and if so, I supply my own, pre-looked-up, Lat/Long. To my knowledge, there\'s no other way.
回答4:
in iOS Simulator menu, go to Debug -> Location -> Custom Location. There you can set the latitude and longitude and test the app accordingly. This works with mapkit and also with CLLocationManager.
回答5:
Pre iOS 5 you could do it in code:
I use this snippet just before the @implementation
of the class where I need my fake heading and location data.
#if (TARGET_IPHONE_SIMULATOR)
@interface MyHeading : CLHeading
-(CLLocationDirection) magneticHeading;
-(CLLocationDirection) trueHeading;
@end
@implementation MyHeading
-(CLLocationDirection) magneticHeading { return 90; }
-(CLLocationDirection) trueHeading { return 91; }
@end
@implementation CLLocationManager (TemporaryLocationFix)
- (void)locationFix {
CLLocation *location = [[CLLocation alloc] initWithLatitude:55.932 longitude:12.321];
[[self delegate] locationManager:self didUpdateToLocation:location fromLocation:nil];
id heading = [[MyHeading alloc] init];
[[self delegate] locationManager:self didUpdateHeading: heading];
}
-(void)startUpdatingHeading {
[self performSelector:@selector(locationFix) withObject:nil afterDelay:0.1];
}
- (void)startUpdatingLocation {
[self performSelector:@selector(locationFix) withObject:nil afterDelay:0.1];
}
@end
#endif
After iOS 5 simply include a GPX file in your project like this to have the location updated continuously Hillerød.gpx:
<?xml version=\"1.0\"?>
<gpx version=\"1.1\" creator=\"Xcode\">
<wpt lat=\"55.93619760\" lon=\"12.29131930\"></wpt>
<wpt lat=\"55.93625770\" lon=\"12.29108330\"></wpt>
<wpt lat=\"55.93631780\" lon=\"12.29078290\"></wpt>
<wpt lat=\"55.93642600\" lon=\"12.29041810\"></wpt>
<wpt lat=\"55.93653420\" lon=\"12.28998890\"></wpt>
<wpt lat=\"55.93660630\" lon=\"12.28966710\"></wpt>
<wpt lat=\"55.93670240\" lon=\"12.28936670\"></wpt>
<wpt lat=\"55.93677450\" lon=\"12.28921650\"></wpt>
<wpt lat=\"55.93709900\" lon=\"12.28945250\"></wpt>
<wpt lat=\"55.93747160\" lon=\"12.28949540\"></wpt>
<wpt lat=\"55.93770000\" lon=\"12.28966710\"></wpt>
<wpt lat=\"55.93785620\" lon=\"12.28977440\"></wpt>
<wpt lat=\"55.93809660\" lon=\"12.28988170\"></wpt>
<wpt lat=\"55.93832490\" lon=\"12.28994600\"></wpt>
<wpt lat=\"55.93845710\" lon=\"12.28996750\"></wpt>
<wpt lat=\"55.93856530\" lon=\"12.29007480\"></wpt>
<wpt lat=\"55.93872150\" lon=\"12.29013910\"></wpt>
<wpt lat=\"55.93886570\" lon=\"12.28975290\"></wpt>
<wpt lat=\"55.93898590\" lon=\"12.28955980\"></wpt>
<wpt lat=\"55.93910610\" lon=\"12.28919500\"></wpt>
<wpt lat=\"55.93861330\" lon=\"12.28883020\"></wpt>
<wpt lat=\"55.93845710\" lon=\"12.28868000\"></wpt>
<wpt lat=\"55.93827680\" lon=\"12.28850840\"></wpt>
<wpt lat=\"55.93809660\" lon=\"12.28842250\"></wpt>
<wpt lat=\"55.93796440\" lon=\"12.28831520\"></wpt>
<wpt lat=\"55.93780810\" lon=\"12.28810070\"></wpt>
<wpt lat=\"55.93755570\" lon=\"12.28790760\"></wpt>
<wpt lat=\"55.93739950\" lon=\"12.28775730\"></wpt>
<wpt lat=\"55.93726730\" lon=\"12.28767150\"></wpt>
<wpt lat=\"55.93707500\" lon=\"12.28760710\"></wpt>
<wpt lat=\"55.93690670\" lon=\"12.28734970\"></wpt>
<wpt lat=\"55.93675050\" lon=\"12.28726380\"></wpt>
<wpt lat=\"55.93649810\" lon=\"12.28713510\"></wpt>
<wpt lat=\"55.93625770\" lon=\"12.28687760\"></wpt>
<wpt lat=\"55.93596930\" lon=\"12.28679180\"></wpt>
<wpt lat=\"55.93587310\" lon=\"12.28719940\"></wpt>
<wpt lat=\"55.93575290\" lon=\"12.28752130\"></wpt>
<wpt lat=\"55.93564480\" lon=\"12.28797190\"></wpt>
<wpt lat=\"55.93554860\" lon=\"12.28833670\"></wpt>
<wpt lat=\"55.93550050\" lon=\"12.28868000\"></wpt>
<wpt lat=\"55.93535630\" lon=\"12.28900190\"></wpt>
<wpt lat=\"55.93515200\" lon=\"12.28936670\"></wpt>
<wpt lat=\"55.93505580\" lon=\"12.28958120\"></wpt>
<wpt lat=\"55.93481550\" lon=\"12.29001040\"></wpt>
<wpt lat=\"55.93468320\" lon=\"12.29033230\"></wpt>
<wpt lat=\"55.93452700\" lon=\"12.29063270\"></wpt>
<wpt lat=\"55.93438280\" lon=\"12.29095450\"></wpt>
<wpt lat=\"55.93425050\" lon=\"12.29121200\"></wpt>
<wpt lat=\"55.93413040\" lon=\"12.29140520\"></wpt>
<wpt lat=\"55.93401020\" lon=\"12.29168410\"></wpt>
<wpt lat=\"55.93389000\" lon=\"12.29189870\"></wpt>
<wpt lat=\"55.93372170\" lon=\"12.29239220\"></wpt>
<wpt lat=\"55.93385390\" lon=\"12.29258530\"></wpt>
<wpt lat=\"55.93409430\" lon=\"12.29295010\"></wpt>
<wpt lat=\"55.93421450\" lon=\"12.29320760\"></wpt>
<wpt lat=\"55.93433470\" lon=\"12.29333630\"></wpt>
<wpt lat=\"55.93445490\" lon=\"12.29350800\"></wpt>
<wpt lat=\"55.93463520\" lon=\"12.29374400\"></wpt>
<wpt lat=\"55.93479140\" lon=\"12.29410880\"></wpt>
<wpt lat=\"55.93491160\" lon=\"12.29419460\"></wpt>
<wpt lat=\"55.93515200\" lon=\"12.29458090\"></wpt>
<wpt lat=\"55.93545250\" lon=\"12.29494570\"></wpt>
<wpt lat=\"55.93571690\" lon=\"12.29505300\"></wpt>
<wpt lat=\"55.93593320\" lon=\"12.29513880\"></wpt>
<wpt lat=\"55.93617360\" lon=\"12.29522460\"></wpt>
<wpt lat=\"55.93622170\" lon=\"12.29537480\"></wpt>
<wpt lat=\"55.93713510\" lon=\"12.29505300\"></wpt>
<wpt lat=\"55.93776000\" lon=\"12.29378700\"></wpt>
<wpt lat=\"55.93904600\" lon=\"12.29531040\"></wpt>
<wpt lat=\"55.94004350\" lon=\"12.29552500\"></wpt>
<wpt lat=\"55.94023570\" lon=\"12.29561090\"></wpt>
<wpt lat=\"55.94019970\" lon=\"12.29591130\"></wpt>
<wpt lat=\"55.94017560\" lon=\"12.29629750\"></wpt>
<wpt lat=\"55.94017560\" lon=\"12.29670520\"></wpt>
<wpt lat=\"55.94017560\" lon=\"12.29713430\"></wpt>
<wpt lat=\"55.94019970\" lon=\"12.29754200\"></wpt>
<wpt lat=\"55.94024780\" lon=\"12.29816430\"></wpt>
<wpt lat=\"55.94051210\" lon=\"12.29842180\"></wpt>
<wpt lat=\"55.94084860\" lon=\"12.29820720\"></wpt>
<wpt lat=\"55.94105290\" lon=\"12.29799270\"></wpt>
<wpt lat=\"55.94123320\" lon=\"12.29777810\"></wpt>
<wpt lat=\"55.94140140\" lon=\"12.29749910\"></wpt>
<wpt lat=\"55.94142550\" lon=\"12.29726310\"></wpt>
<wpt lat=\"55.94147350\" lon=\"12.29687690\"></wpt>
<wpt lat=\"55.94155760\" lon=\"12.29619020\"></wpt>
<wpt lat=\"55.94161770\" lon=\"12.29576110\"></wpt>
<wpt lat=\"55.94148550\" lon=\"12.29531040\"></wpt>
<wpt lat=\"55.94093270\" lon=\"12.29522460\"></wpt>
<wpt lat=\"55.94041600\" lon=\"12.29518170\"></wpt>
<wpt lat=\"55.94056020\" lon=\"12.29398010\"></wpt>
<wpt lat=\"55.94024780\" lon=\"12.29352950\"></wpt>
<wpt lat=\"55.94001940\" lon=\"12.29335780\"></wpt>
<wpt lat=\"55.93992330\" lon=\"12.29325050\"></wpt>
<wpt lat=\"55.93969490\" lon=\"12.29299300\"></wpt>
<wpt lat=\"55.93952670\" lon=\"12.29277840\"></wpt>
<wpt lat=\"55.93928630\" lon=\"12.29260680\"></wpt>
<wpt lat=\"55.93915410\" lon=\"12.29232780\"></wpt>
<wpt lat=\"55.93928630\" lon=\"12.29202740\"></wpt>
<wpt lat=\"55.93933440\" lon=\"12.29174850\"></wpt>
<wpt lat=\"55.93947860\" lon=\"12.29116910\"></wpt>
<wpt lat=\"55.93965890\" lon=\"12.29095450\"></wpt>
<wpt lat=\"55.94001940\" lon=\"12.29061120\"></wpt>
<wpt lat=\"55.94041600\" lon=\"12.29084730\"></wpt>
<wpt lat=\"55.94076450\" lon=\"12.29101890\"></wpt>
<wpt lat=\"55.94080060\" lon=\"12.29065410\"></wpt>
<wpt lat=\"55.94086060\" lon=\"12.29031080\"></wpt>
<wpt lat=\"55.94092070\" lon=\"12.28990310\"></wpt>
<wpt lat=\"55.94099280\" lon=\"12.28975290\"></wpt>
<wpt lat=\"55.94119710\" lon=\"12.28986020\"></wpt>
<wpt lat=\"55.94134130\" lon=\"12.28998890\"></wpt>
<wpt lat=\"55.94147350\" lon=\"12.29007480\"></wpt>
<wpt lat=\"55.94166580\" lon=\"12.29003190\"></wpt>
<wpt lat=\"55.94176190\" lon=\"12.28938810\"></wpt>
<wpt lat=\"55.94183400\" lon=\"12.28893750\"></wpt>
<wpt lat=\"55.94194220\" lon=\"12.28850840\"></wpt>
<wpt lat=\"55.94199030\" lon=\"12.28835820\"></wpt>
<wpt lat=\"55.94215850\" lon=\"12.28859420\"></wpt>
<wpt lat=\"55.94250700\" lon=\"12.28883020\"></wpt>
<wpt lat=\"55.94267520\" lon=\"12.28893750\"></wpt>
<wpt lat=\"55.94284350\" lon=\"12.28902330\"></wpt>
<wpt lat=\"55.94304770\" lon=\"12.28915210\"></wpt>
<wpt lat=\"55.94325200\" lon=\"12.28925940\"></wpt>
<wpt lat=\"55.94348030\" lon=\"12.28953830\"></wpt>
<wpt lat=\"55.94366060\" lon=\"12.28966710\"></wpt>
<wpt lat=\"55.94388890\" lon=\"12.28975290\"></wpt>
<wpt lat=\"55.94399700\" lon=\"12.28994600\"></wpt>
<wpt lat=\"55.94379280\" lon=\"12.29065410\"></wpt>
<wpt lat=\"55.94364860\" lon=\"12.29095450\"></wpt>
<wpt lat=\"55.94350440\" lon=\"12.29127640\"></wpt>
<wpt lat=\"55.94340820\" lon=\"12.29155540\"></wpt>
<wpt lat=\"55.94331210\" lon=\"12.29198450\"></wpt>
<wpt lat=\"55.94315590\" lon=\"12.29269260\"></wpt>
<wpt lat=\"55.94310780\" lon=\"12.29318610\"></wpt>
<wpt lat=\"55.94301170\" lon=\"12.29361530\"></wpt>
<wpt lat=\"55.94292760\" lon=\"12.29408740\"></wpt>
<wpt lat=\"55.94290350\" lon=\"12.29436630\"></wpt>
<wpt lat=\"55.94287950\" lon=\"12.29453800\"></wpt>
<wpt lat=\"55.94283140\" lon=\"12.29533190\"></wpt>
<wpt lat=\"55.94274730\" lon=\"12.29606150\"></wpt>
<wpt lat=\"55.94278340\" lon=\"12.29621170\"></wpt>
<wpt lat=\"55.94280740\" lon=\"12.29649060\"></wpt>
<wpt lat=\"55.94284350\" lon=\"12.29679100\"></wpt>
<wpt lat=\"55.94284350\" lon=\"12.29734890\"></wpt>
<wpt lat=\"55.94308380\" lon=\"12.29837890\"></wpt>
<wpt lat=\"55.94315590\" lon=\"12.29852910\"></wpt>
<wpt lat=\"55.94263920\" lon=\"12.29906550\"></wpt>
<wpt lat=\"55.94237480\" lon=\"12.29910850\"></wpt>
<wpt lat=\"55.94220660\" lon=\"12.29915140\"></wpt>
<wpt lat=\"55.94208640\" lon=\"12.29902260\"></wpt>
<wpt lat=\"55.94196620\" lon=\"12.29887240\"></wpt>
<wpt lat=\"55.94176190\" lon=\"12.29794970\"></wpt>
<wpt lat=\"55.94156970\" lon=\"12.29760640\"></wpt>
</gpx>
I use GPSies.com to create the base file for the gpx data. A bit of cleanup is required though.
Activate by running the simulator and choosing your file
http://castleandersen.dk/keepers/location.png
回答6:
The kind folks at FutureTap have made the FTLocationSimulator available for free at GitHub. It allows you to prepare a test route using for instance Google Earth, and then have the simulator feed these coordinates to your app.
I\'ve written a blog post about how to use FTLocationSimulator to easily switch between multiple routes during testing of the location features.
回答7:
you can add gpx files to your project and use it:
edit scheme > options > allow location simulation > pick the file name that contains for example:
<?xml version=\"1.0\"?>
<gpx version=\"1.1\" creator=\"Xcode\">
<wpt lat=\"41.92296\" lon=\"-87.63892\"></wpt>
</gpx>
optionally just hardcode the lat/lon values that are returned by the location manager. This is old style though.
so you won\'t add it to the simulator, but to your Xcode project.
回答8:
Open iOS Simulator application from Debug Menu -> Location ->
- None
- Custom Location
- Apple Stores ...
回答9:
Better late than never :)
I just came across this iSimulate which allows you to send Fake location to the app. The solution is NOT free.
> Q: How does iSimulate work?
> A: When added to your project, the iSimulate
> SDK library creates a listening server
> on your iPhone Simulator that waits
> for a connection from an iPhone/iPod
> running the iSimulate client. When
> such connection is established, the
> iSimulate client running on your
> iPhone/iPod captures all data from the
> accelerometer sensor, the touch
> events, the location and device ID and
> streams them to the server. The
> iSimulate SDK library then recreates
> all input events synthetically. This
> is entirely transparent to your
> application and does not interfere
> with your application\'s functionality.
Anyway, i am planning to get this. will update more soon!
回答10:
Where you want to set your location? you can use mapkit api to show u location\'s. see icodeblog.com for more detail on how to use mapkit. Also you can store your desired cordinates just create an object CLLocation2D *location; location.longitude=your desired longitude value; location.latitude=your desired latitude value;