巧妙地使用iPhone模拟器更好地测试GPS代码?

Glo*_*ria 2 iphone gps core-location mapkit ios

我一直在玩iPhone SDK,使用MapKit和Core Location.

你可以使用哪些技巧来更好地测试...同时仍然在模拟器上(很久以前我必须在我的iPhone上试用它).

有没有办法使用NSTimer并定期获取位置,航向,速度等"假装"值?

模拟器只提供1个位置......并且没有移动...真正限制了它的"测试"实用性.

Joe*_*oey 6

这是接收GPS数据的正常方式.

[GPS模块] ----(CLLocationManagerDelegate)---> [YourLocationManager类]

locationManager:didUpdateToLocation:fromLocation:

此方法将接收数据.


您还可以在Test类的YourLocationManager类上调用相同的方法.

[Test class] --------调用------> [YourLocationManager类]

1 ..使这样的CLLocation对象.....在Test类上

CLLocationCoordinate2D location;
location.latitude = 37.0;
location.longitude = 127.0;

CLLocation *sampleLocation = [[CLLocation alloc] initWithCoordinate: location
        altitude:100
        horizontalAccuracy:100
        verticalAccuracy:100 
        timestamp:[NSDate date]];

您只能设置纬度,经度,海拔高度,水平精度,垂直精度,时间戳.

你不能设定...当然,速度.

2 ..调用locationManager:didUpdateToLocation:fromLocation:来自Test类的YourLocationmanager类的方法.

[yourLocationManager locationManager: nil or something
                     didUpdateToLocation: sampleLocation
                     fromLocation: sampleLocation or nil or something];

您可以使用NSTimer发送更多数据!

  • `[[CLLocation init] initWithCoordinate:...]`应该是`[[CLLocation alloc] initWithCoordinate:...]` (3认同)