`

让模拟器也支持GPS定位(模拟实现)

阅读更多
iOS上的GPS定位一般需要真机才能看到效果,但在开发的过程中,一般都在模拟器上调试。那怎么办呢?我们可以使用Object-C的策略,给模拟器指定一个经纬度,这样,定位就可以在模拟器上实现了。RealTool为你实现一个简单的demo。

// 模拟器 宏定义
#ifdef TARGET_IPHONE_SIMULATOR
@interface CLLocationManager (Simulator)
@end

@implementation CLLocationManager (Simulator)

-(void)startUpdatingLocation
{
    float latitude = 32.061;
    float longitude = 118.79125;   
    CLLocation *setLocation= [[[CLLocation alloc] initWithLatitude:latitude longitude:longitude] autorelease];
    [self.delegate locationManager:self didUpdateToLocation:setLocation
                      fromLocation:setLocation];
}
@end
#endif // TARGET_IPHONE_SIMULATOR

这样,在调用startUpdatingLocation的时候,就会自己调用返回经纬度的函数了。
分享到:
评论
发表评论

文章已被作者锁定,不允许评论。

相关推荐

Global site tag (gtag.js) - Google Analytics