IOS 火星坐标转凯立德K码
2016-12-10 本文已影响15人
Jackson_Z
+(NSString *) EncodeLat:(double)lat lon:(double)lon {
lat = lat * 1000000;
lon = lon * 1000000;
NSString *k;
lon -= 70000000;
lat -= 5000000;
if (lat > 35000000){
if (lon <= 35000000) {
k = @"6";
} else {
k = @"5";
}
}else
if (lon <= 35000000) {
k = @"7";
}else {
k = @"8";
}
if (lon > 35000000) {
lon -= 35000000;
}
if (lat > 35000000) {
lat -= 35000000;
}
k = [k stringByAppendingString:[self encode:lon]];
k = [k stringByAppendingString:[self encode:lat]];
return k;
}
+(NSString *)encode:(double)v {
NSString *codes = @"0123456789abcdefghijkmnpqrstuvwxyz";
NSString *pch = @"";
v = v * 9 / 250;
for (int i = 0; i < 4; ++i) {
int location = abs((int)v%34);
NSString *str = [codes substringWithRange:NSMakeRange(location, 1)];
//NSString *str = [NSString stringWithFormat:@"%d",[codes characterAtIndex:(int)v%34]];
pch = [pch stringByAppendingString:str];
v /= 34;
}
return pch;
}