Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set location simulator City/GPX during Runtime

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?

enter image description here

like image 658
loop Avatar asked Jul 13 '16 12:07

loop


People also ask

How do I change my location in simulator?

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.

How do I change the default location in iOS simulator?

in iOS Simulator menu, go to Debug -> Location -> Custom Location. There you can set the latitude and longitude and test the app accordingly.

How do you use location in simulator?

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.

How do I enable location services on Iphone simulator?

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.


1 Answers

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.

like image 174
SaRaVaNaN DM Avatar answered Sep 18 '22 05:09

SaRaVaNaN DM