简体   繁体   English

在运行时设置位置模拟器City / GPX

[英]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. 下图显示了如何手动切换位置(GPX文件)。 How can I achieve this result programmatically while the app is running? 如何在应用程序运行时以编程方式实现此结果?

在此输入图像描述

Alternate way to set location is by swizzling 'location' of 'CLLocationManager' class. 设置位置的替代方法是通过调用“CLLocationManager”类的“位置”。 In obj-c, 在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. 然后通过简单地更改“kMockedLatitude”和“kMockedLongitude”变量,使用您想要设置的任何位置实现custom_location方法。

//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. 这甚至可以在iOS设备中使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM