0

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

4

2 回答 2

1
- (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
于 2013-03-15T13:23:09.797 回答
0

如果您使用的是 mongo,这很容易,您可以使用 $nearSphere for mysql 遵循这些教程

https://developers.google.com/maps/articles/phpsqlsearch_v3

http://www.phpro.org/tutorials/Geo-Targetting-With-PHP-And-MySQL.html

所有教程都在 mysql 和 php 中

于 2013-03-15T07:03:18.700 回答