简介:本文是基于项目需要,分别采用的3种获取用户位置的方法,各有优略,自行斟酌。
第一种,使用mapkit获取用户经纬度,使用google解析经纬度获取地址,代码如下:
#import "LocationHelper.h"
#import <MapKit/MapKit.h>
#import "JSONKit.h"
#import "ASIFormDataRequest.h"
@interface LocationHelper()<MKMapViewDelegate>
{
MKMapView *dgMapView;
BOOL isLocationing; //是否正在定位
};
@end
@implementation LocationHelper
static LocationHelper *singleTon2;
+(LocationHelper *)shareHelper
{
@synchronized (self)
{
if (singleTon2 == nil)
{
singleTon2 = [[[self alloc] init] autorelease];
}
}
return singleTon2;
}
+(id)allocWithZone:(NSZone *)zone
{
@synchronized (self) {
if (singleTon2 == nil) {
singleTon2 = [super allocWithZone:zone];
return singleTon2;
}
}
return nil;
}
+(id)copyWithZone:(NSZone *)zone
{
return self;
}
-(id)retain{
return self;
}
-(NSUInteger)retainCount
{
return NSUIntegerMax;
}
-(oneway void)release
{
//do nothing
}
-(id)autorelease
{
return self;
}
-(id)init
{
if (self=[super