我正在开发一个应用程序。我希望从一个位置到另一个位置获取所有位置。我知道两个位置的纬度和经度值。所以如何从第一个位置到第二个位置获取所有位置详细信息。 / p>
答案 0 :(得分: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
答案 1 :(得分: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中