Is there a method to programmatically change the location simulator city during runtime? For example this would allow tests to simulate London or Tokyo.
The image below shows how to switch between locations (GPX files) manually. How can I achieve this result programmatically while the app is running?
How to simulate location in Simulator. To simulate location on a Simulator, select Features menu > Location, then you will see a list of location and movement options you can simulate.
in iOS Simulator menu, go to Debug -> Location -> Custom Location. There you can set the latitude and longitude and test the app accordingly.
Go to the desired floor in the Meridian Map Editor. Click the location on the map you want to simulate, and then press the lowercase L key. A dialog will appear with the message, “Simulated Location Set”. After a short time, the simulated location you set in the Editor will appear as a pink dot in the Android Emulator.
For simulating location, goto your Target → Edit scheme . Then under the Run scheme, select options tab. As you can see in the image below, the Allow location simulation checkbox should be enabled. Then you can choose a default location from the drop down.
Alternate way to set location is by swizzling 'location' of 'CLLocationManager' class. In obj-c,
+(void) load {
// replace 'location' with 'custom_location' method
}
Then implement custom_location method with whatever the location you want to set by simply changing 'kMockedLatitude' and 'kMockedLongitude' variables.
//Portland, USA
CLLocationDegrees kMockedLatitude = 45.52306;
CLLocationDegrees kMockedLongitude = -122.67648;
-(CLLocation *)custom_location
{
return [[CLLocation alloc] initWithLatitude:kMockedLatitude longitude:kMockedLongitude];
}
This will work even in iOS device.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With