IOS 火星坐标转凯立德K码
作者:
Jackson_Z | 来源:发表于
2016-12-10 10:12 被阅读15次+(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;
}
本文标题:IOS 火星坐标转凯立德K码
本文链接:https://www.haomeiwen.com/subject/zpgymttx.html
网友评论