Iphone 获取范围内具有的位置详细信息

Iphone 获取范围内具有的位置详细信息,iphone,Iphone,我正在开发一个应用程序。我想从一个位置到另一个位置获取所有位置。我知道两个位置的纬度和经度值。因此,如何从第一个位置到第二个位置获取所有位置的详细信息。如果您使用mongo,您可以使用$nearSphere for mysql。请遵循以下教程 所有教程都是mysql和php的-(void)getCordinate:(NSString*)strOrigin:(NSString*)strDestination - (void)getCordinate :(NSString *)strOrigin

我正在开发一个应用程序。我想从一个位置到另一个位置获取所有位置。我知道两个位置的纬度和经度值。因此,如何从第一个位置到第二个位置获取所有位置的详细信息。

如果您使用mongo,您可以使用$nearSphere for mysql。请遵循以下教程

所有教程都是mysql和php的

-(void)getCordinate:(NSString*)strOrigin:(NSString*)strDestination
- (void)getCordinate :(NSString *)strOrigin : (NSString*)strDestination
{
    NSMutableString *tempStrOrigin = [NSMutableString stringWithString:strOrigin];
    NSMutableString *tempStrDestination = [NSMutableString stringWithString:strDestination];

    //[tempStrOrigin replaceOccurrencesOfString:@" " withString:@"+" options:NULL range:[NSMakeRange(0, [tempStrOrigin length])]];

    tempStrOrigin = [[tempStrOrigin stringByReplacingOccurrencesOfString:@" " withString:@"+"] mutableCopy];
    tempStrDestination = [[tempStrDestination stringByReplacingOccurrencesOfString:@" " withString:@"+"] mutableCopy];

    NSString *url = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/directions/json?origin=%@&destination=%@&sensor=false&mode=walking",tempStrOrigin,tempStrDestination];
    NSLog(@"URL:%@",url);

    NSURLConnection *urlConnection = [NSURLConnection connectionWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]] delegate:self];
    if (urlConnection == nil)
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Pradeep Chakoriya" message:@"Connection Failed !" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
        [alert release];
    }
}


- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    NSLog(@"Connection finish!!!");
    NSError *error = nil;
    NSMutableString *str = [[NSMutableString alloc]initWithData:responeData encoding:NSUTF8StringEncoding];
    NSLog(@"Response in String:%@",str);

    SBJsonParser *parser=[[SBJsonParser alloc] init];

    NSDictionary *jsonObject = [parser objectWithString:str];
    NSLog(@"Error:%@",error);
    NSLog(@"Response Object:%@",jsonObject);

    NSLog(@"End location:%@",[jsonObject valueForKeyPath:@"routes.legs.end_location"]);
    NSLog(@"Start location:%@",[jsonObject valueForKeyPath:@"routes.legs.start_location.lat"]);
NSLog(@"Overview_polyline:%d",[[jsonObject valueForKeyPath:@"routes.overview_polyline.points"] count]);
NSString *strTemp = [NSString stringWithFormat:@"%@",[[jsonObject valueForKeyPath:@"routes.overview_polyline.points"] objectAtIndex:0]];
        NSLog(@"String Temp:%@",strTemp);

        NSLog(@"Decode points:%@",[[[self decodePolyLine:strTemp] objectAtIndex:0] class]);
}

-(NSMutableArray *)decodePolyLine:(NSString *)encodedStr {
    NSMutableString *encoded = [[NSMutableString alloc] initWithCapacity:[encodedStr length]];
    NSLog(@"encoded:%@",encoded);
    [encoded appendString:encodedStr];
    NSLog(@"encoded:%@",encoded);
    /*[encoded replaceOccurrencesOfString:@"\\\\" withString:@"\\"
                                options:NSLiteralSearch
                                  range:NSMakeRange(0, [encoded length])];*/
    NSInteger len = [encoded length];
    NSInteger index = 0;
    NSMutableArray *array = [[[NSMutableArray alloc] init] autorelease];
    NSInteger lat=0;
    NSInteger lng=0;
    while (index < len) {
        NSInteger b;
        NSInteger shift = 0;
        NSInteger result = 0;
        do {
            b = [encoded characterAtIndex:index++] - 63;
            result |= (b & 0x1f) << shift;
            shift += 5;
        } while (b >= 0x20);
        NSInteger dlat = ((result & 1) ? ~(result >> 1) : (result >> 1));
        lat += dlat;
        shift = 0;
        result = 0;
        do {
            b = [encoded characterAtIndex:index++] - 63;
            result |= (b & 0x1f) << shift;
            shift += 5;
        } while (b >= 0x20);
        NSInteger dlng = ((result & 1) ? ~(result >> 1) : (result >> 1));
        lng += dlng;
        NSNumber *latitude = [[[NSNumber alloc] initWithFloat:lat * 1e-5] autorelease];
        NSNumber *longitude = [[[NSNumber alloc] initWithFloat:lng * 1e-5] autorelease];
        //          printf("[%f,", [latitude doubleValue]);
        //          printf("%f]", [longitude doubleValue]);
        CLLocation *loc = [[[CLLocation alloc] initWithLatitude:[latitude floatValue] longitude:[longitude floatValue]] autorelease];
        [array addObject:loc];
    }
    [encoded release];
    return array;
}

Use this code to get all latitute and longitute of origin to destination
{ NSMutableString*tempStrOrigin=[NSMutableString stringWithString:strOrigin]; NSMutableString*tempStrDestination=[NSMutableString-stringWithString:strDestination]; //[tempStrOrigin REPLACEOCURNCESOFSTRING:@”“带字符串:@“+”选项:空范围:[NSMakeRange(0,[tempStrOrigin长度]])]; tempStrOrigin=[[tempStrOrigin stringByReplacingOccurrencesOfString:@”“with string:@“+”]mutableCopy]; tempStrDestination=[[tempStrDestination stringByReplacingOccurrencesOfString:@”“with string:@“+”]mutableCopy]; NSString*url=[NSString stringWithFormat:@”http://maps.googleapis.com/maps/api/directions/json?origin=%@&目的地=%@&sensor=false&mode=walking“,tempStrOrigin,tempStrDestination]; NSLog(@“URL:%@”,URL); NSURLConnection*urlConnection=[NSURLConnection connectionWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]委托:自我]; if(urlConnection==nil) { UIAlertView*alert=[[UIAlertView alloc]initWithTitle:@“Pradeep Chakoriya”消息:@“连接失败!”委托:自取消按钮:@“确定”其他按钮:无,无]; [警报显示]; [警报发布]; } } -(无效)连接IDFinishLoading:(NSURLConnection*)连接 { NSLog(@“连接完成!!!”); n错误*错误=nil; NSMutableString*str=[[NSMutableString alloc]initWithData:responeData编码:NSUTF8StringEncoding]; NSLog(@“字符串中的响应:%@”,str); SBJsonParser*parser=[[SBJsonParser alloc]init]; NSDictionary*jsonObject=[parser objectWithString:str]; NSLog(@“错误:%@”,错误); NSLog(@“响应对象:%@”,jsonObject); NSLog(@“结束位置:%@,[jsonObject valueForKeyPath:@“routes.legs.End_location”]); NSLog(@“开始位置:%@,[jsonObject valueForKeyPath:@”routes.legs.Start_location.lat“]); NSLog(@“概述”\u多段线:%d”,[[jsonObject valueForKeyPath:@“路由.概述”\u多段线.点”]计数]; NSString*strTemp=[NSString stringWithFormat:@“%@,[[jsonObject valueForKeyPath:@”路由。概述\u多段线。点“]objectAtIndex:0]]; NSLog(@“字符串温度:%@”,strTemp); NSLog(@“解码点:%@,[[self-decodePolyLine:strTemp]objectAtIndex:0]class]); } -(NSMutableArray*)解码多段线:(NSString*)编码器{ NSMutableString*encoded=[[NSMutableString alloc]initWithCapacity:[EncodedStrength]]; NSLog(@“编码:%@”,编码); [encoded appendString:encodedStr]; NSLog(@“编码:%@”,编码); /*[encoded ReplaceAccurrencesofString:@“\\\\”和字符串:@“\\” 选项:NSLiteralSearch 范围:NSMakeRange(0,[编码长度])*/ NSInteger len=[编码长度]; NSInteger指数=0; NSMutableArray*数组=[[[NSMutableArray alloc]init]autorelease]; NSInteger-lat=0; NSInteger液化天然气=0; while(指数>1):(结果>>1)); lat+=dlat; 移位=0; 结果=0; 做{ b=[编码字符索引:索引++]-63; 结果|=(b&0x1f)=0x20); NSInteger dlng=((结果&1)~(结果>>1):(结果>>1)); 液化天然气+=液化天然气; NSNumber*纬度=[[NSNumber alloc]initWithFloat:lat*1e-5]自动释放]; NSNumber*经度=[[NSNumber alloc]initWithFloat:lng*1e-5]自动释放]; //printf(“[%f,,[latitude doubleValue]); //printf(“%f]”,[longitude doubleValue]); CLLocation*loc=[[CLLocation alloc]initWithLatitude:[纬度浮动值]经度:[经度浮动值]]自动释放]; [数组addObject:loc]; } [编码释放]; 返回数组; } 使用此代码获取从起点到目的地的所有纬度和经度
im不是移动应用程序开发人员,但方法是一样的。你需要从数据库或其他地方获取位置列表,找到接近目标值的lat和long值,并按lat和long的顺序对它们进行排序。你想在两个位置之间选择哪种位置?或者你想显示这两个位置之间的直线?我想知道获取两个位置之间的Restreents列表。结果以从起点到终点的纬度和经度数组返回