我正在尝试在两个位置之间绘制路线。为此,我有两个CLLocation
(startPoint ,endPoint)
。在MKReverseGeocoder
这两个位置之后,我像这样出去了。
- (void)findAddress{
geoCoder1 = [[MKReverseGeocoder alloc] initWithCoordinate:startPoint.coordinate];
geoCoder1.delegate = self;
[geoCoder1 start];
geoCoder2 = [[MKReverseGeocoder alloc] initWithCoordinate:endPoint.coordinate];
geoCoder2.delegate = self;
[geoCoder2 start];
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{
if(geocoder==geoCoder1){
NSMutableDictionary *cplace1=[[[NSMutableDictionary alloc]initWithDictionary:[placemark addressDictionary]] autorelease];
NSLog(@"The MKReverseGeocoder Start Point Address %@", cplace1 );
}else{
NSMutableDictionary *cplace2=[[[NSMutableDictionary alloc]initWithDictionary:[placemark addressDictionary]] autorelease];
NSLog(@"The MKReverseGeocoder End Point Address %@", cplace2 );
}
}
输出:-
The MKReverseGeocoder Start Point Address {
City = Bangalore;
Country = India;
CountryCode = IN;
FormattedAddressLines = (
"Grant Rd, Sampangi Rama Nagar",
"Bangalore, Karnataka",
India
);
State = Karnataka;
Street = "Grant Rd";
SubAdministrativeArea = "Bengaluru Rural";
SubLocality = "Sampangi Rama Nagar";
Thoroughfare = "Grant Rd";
}
The MKReverseGeocoder End Point Address {
Country = India;
CountryCode = IN;
FormattedAddressLines = (
"NH47 Bi - Rd",
"Ernakulam, Kerala",
India
);
State = Kerala;
Street = "NH47 Bi - Rd";
SubAdministrativeArea = Ernakulam;
Thoroughfare = "NH47 Bi - Rd";
}
现在我想检索这两个位置之间的路线点,为此我NSURLRequest
是这样发送的。
- (void)updateRoute {
NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:
@"http://maps.googleapis.com/maps/api/directions/json?origin=%@&destination=%@&mode=%@&sensor=false", startLocation,endLocation,routeMode] ]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
问题是我想通过startLocation
和endLocation
去NSURLRequest
。那么我应该分配哪些值startLocation
,以及endLocation
从MKReverseGeocoder
委托返回(cplace1 和 cplace2)?