首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

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

2012-06-29 
让模拟器也支持GPS定位(模拟实现)iOS上的GPS定位一般需要真机才能看到效果,但在开发的过程中,一般都在模拟

让模拟器也支持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的时候,就会自己调用返回经纬度的函数了。

热点排行