Set the location in iPhone Simulator
Asked Answered
A

18

172

How can I set the location (as it's picked up in CoreLocation services) in the iPhone Simulator?

Allistir answered 18/10, 2008 at 2:15 Comment(3)
I added a method for Xcode 6. #19694705Barbabas
Has anyone managed to get this to work in React native, simulator?Seditious
With iOS 13 beta 2, I could only see "None" and "Custom" options. Is any one else having this issue? stackoverflow.com/q/56733625/1364053Uprising
S
139

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!

Selfsame answered 17/11, 2011 at 22:46 Comment(7)
where is debug menu in IOS simulator?Untimely
this works but it's for the debug menu on the simulator not the one on xcodeFruiter
For iOS simulator, it is now located under "Features"Provision
For recent version of simulator using iOS 15.2, "Location" is now under the Features menuTide
I'm running the iphone 12 emulator and there are only two options for location, None and Custom. Should I try another emulator?Pascoe
Bicycle ride, City Run, and Freeway Drive are simulation of a moving location (in Cupertino, of course) My question is why only in Cupertino, why not anywhere else?Proteinase
@Proteinase Because Apple is in Cupertino, as in "One Apple Park Way, Cupertino, California"Selfsame
S
91
  1. Run project in iPhone Simulator
  2. Create in TextEdit file following file, call it MyOffice for example. Make extension as .gpx enter image description here

    <?xml version="1.0"?> <gpx version="1.0" creator="MyName"> <wpt lat="53.936166" lon="27.565370"> <name>MyOffice</name> </wpt> </gpx>

  3. Select in Xcode at the Simulate area Add GPX File to Project...enter image description here

  4. Add created file from menu to project.
  5. Now you can see your location in Simulate area:enter image description here
Solnit answered 28/9, 2012 at 9:44 Comment(7)
TextEdit doesn't save file .gpx. How I do?Penalize
save it as .txt (or .xml) and then rename to .gpxSolnit
Thanks! Very easy, works great. In case anyone else uses this heres the sample GPX file in text so you can copy & paste it: <?xml version="1.0"?> <gpx version="1.0" creator="Name"> <wpt lat="" lon=""> <name>Office</name> </wpt> </gpx>Jorie
can we include time in this? I want to test startMonitoringSignificantLocationChanges methodBriant
Here's a helpful post on doing more with GPX files: blackpixel.com/blog/2013/05/…Elative
i cant create new file ....error like this ...You cannot save this document with extension “.gpx” at the end of the name. The required extension is “.rtf”.Gavial
Saved my loads of Efforts +1Pinfeather
A
63

XCode 11.3 and prior:

Debug -> Location -> Custom Location

enter image description here

XCode 11.4+:

Features -> Location -> Custom Location

enter image description here

To find out which XCode version you have

$ /usr/bin/xcodebuild -version
Allege answered 14/4, 2020 at 12:13 Comment(1)
Thanks. This is the latest instruction you should followDisulfide
S
27

in iOS Simulator menu, go to Features -> Location -> Custom Location. There you can set the latitude and longitude and test the app accordingly. This works with mapkit and also with CLLocationManager.

Siusiubhan answered 6/7, 2015 at 5:7 Comment(1)
In version 12.1 of the simulator it is in Features -> Location -> Custom LocationHaldane
K
17

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.

Kenzie answered 18/10, 2008 at 2:51 Comment(1)
Starting with Xcode 4.2, there is now a way under the Debug menu on the simulator using the Location entry that allows setting a custom location or selecting from some predefined rides and locations.Colston
T
12

You can easily share any desired location from the macOS Maps application to the Xcode simulator.

  1. From Xcode run the application in the simulator as you usually do.
  2. Open the maps application on macOS (for convenience I usually make a new Desktop where I have both the simulator and the map application).
  3. Inside the maps (macOS), long click on any point on the map, or search for a place to let the map draw a pin where you need it.
  4. Click on the pin, then on the information (i) icon (see image).
  5. In the up right of the information view click on the share icon.
  6. Share the location with the simulator (see image).
  7. Confirm and enjoy :)

This let you test some locations quickly, having an understanding on where geographically the location is (e.g. for testing geofencing), and deciding at runtime where to go next (e.g. for debugging and fine-tuning stuff).

Tested this on MacOS Catalina 10.15.4 and Xcode 11.4.

Tourism answered 30/3, 2020 at 17:28 Comment(1)
bravo! This inconvinient feature blows my mind for all these years. I mean when you need to set a location manually each time. I'm always asking myself, why apple doesnt make simple Favourites list of location where one can add any location he uses and then switch between them easily.Confuse
E
6

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


(source: castleandersen.dk)

Eu answered 10/2, 2012 at 12:6 Comment(0)
I
6

As of Xcode 11.6 and Swift 5.3, facility to simulate custom location has been moved from "Debug" to "Features" in iOS Simulator menu.

Infiltration answered 17/8, 2020 at 7:20 Comment(0)
W
5

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.

Wicketkeeper answered 19/8, 2011 at 4:38 Comment(2)
How can i use the predefined location. can u please explain in detail ??? I want to know about it.Northernmost
click on xcode then product > schemes > Edit scheme > core locationJanerich
E
4

Open iOS Simulator application from Debug Menu -> Location ->

  1. None
  2. Custom Location
  3. Apple Stores ...
Evelynneven answered 16/10, 2014 at 10:17 Comment(0)
I
3

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.

Inveterate answered 21/2, 2011 at 9:20 Comment(0)
E
3

As of the writing of this, the location option for IOS simulator has been moved to Features -> Location -> Custom Location

Explicate answered 26/3, 2020 at 23:31 Comment(0)
S
3

In Xcode itself (not the Simulator app), a simulated location can be set via Debug menu > Simulate Location.

That menu option becomes enabled when the app is actively running (either on the Simulator, or on a real device).

XCode > Debug menu > Simulate Location > Child menu with list of locations

(As of XCode 13.0)

Sombrero answered 15/10, 2021 at 14:23 Comment(0)
T
2

As of iOS 15.2 and Xcode 13.2.2, the simulator has a configurable location.

Under the Features menu, the last entry is "Location"; this gives you a sub menu with:

None
Custom Location
City Run
City Bicycle Ride
Freeway Drive
Apple

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).

Tide answered 6/2, 2022 at 7:48 Comment(0)
S
0

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!

Shrivel answered 29/8, 2009 at 14:31 Comment(2)
I just contacted the developers: "In the Options of iSimulate, accessible from the top-right button in the "Select Computer to Connect to" screen, you can select one of four other locations to use." So, not much help really.Mazard
bitbucket.org/gnucoop/xamarin-ios-simulator-enhancements This helps simulating locations for freeCollodion
S
0

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;

Sweat answered 7/11, 2009 at 8:19 Comment(1)
This was an old question from when I wasnew to the SDK. I now realize there is no support for automating CoreLocation in the Simulator, which is a shame.Allistir
U
0

Changing Location of simulator does not affect already built, loaded apps. For example, if you have an app with Google map view running on simulator the map won't be updated till you rebuild the app. Also, keep in mind that when entering custom lat and long you should be careful with longitudes with (-) sign and without. Replacing existing custom longitude of the simulator with new one but keeping (-) sign mistakenly or entering incorrect lat/long will result empty map screen with blue background - probably indicates oceans or poles.

Urogenous answered 25/9, 2021 at 6:16 Comment(0)
P
-1

Here is a Good place to look into

go to Debug Menu and Simulate Location

https://sarunw.com/posts/how-to-simulate-location-in-xcode-and-simulator/

Prima answered 29/3, 2023 at 20:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.