9

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

loop
  • 1,455
  • 3
  • 13
  • 25

1 Answers1

1

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.

SaRaVaNaN DM
  • 4,390
  • 4
  • 22
  • 30
  • Any way to accomplish this with using only GPX files? The files have complex waypoint routes and timing so overriding Cllocafion would not work. – loop Jul 13 '16 at 13:22
  • This won't work with GPX. But it's one of the way to change location programmatically. I was doing this for one of my project. – SaRaVaNaN DM Jul 13 '16 at 13:27
  • try this http://stackoverflow.com/questions/38493642/automating-xcode-debug-simulate-location-command/38632244#38632244 – SaRaVaNaN DM Jul 29 '16 at 07:29
  • @SaRaVaNaNDM Can you please guide me how I can change location on runtime? I'm using .gpx file for this purpose but I can change the location from Xcode. – Honey Honey Jan 23 '21 at 16:17
  • @SaRaVaNaNDM I want to change location according to user entered Longitude and Latitude. – Honey Honey Jan 23 '21 at 16:20