私は2つの場所の間にルートを描こうとしています。そのために私は2つを持っていますCLLocation
(startPoint ,endPoint)
。この2つの場所のMKReverseGeocoder
の後、私はこのように置いた。CLLocation CordinateでReverseGeocoderを実行した後、Google Map Webサービスに正確な場所を教えてください。
- (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
を送っているため、この2つの場所の間でルートポイントを取得します。
- (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];
}
問題は、私がNSURLRequest
にstartLocation
とendLocation
を渡したいました。だから私はstartLocation
とendLocation
MKReverseGeocoder
代理人の返品(cplace1とcplace2)から割り当てる必要がありますか?
でフォーマットされた文字列の中にそれを置くことができるように
CLLocationDegrees
は、本当に二重のです。あなたの欠けている "座標"すなわちstartPoint.coordinate.latitude、startPoint.coordinate.longitude、endPoint.coordinate.latitude、endPoint.coordinate.latitude – Musthafa位置座標のためのMKReverseGeocoderは不要です。 – Musthafa
ああ、そうです。私は 'CLLocationCoordinate2D'と' CLLocation'を混在させました。逆ジオコーダーの必要はありません。すでに正確な場所があるからです。ここにコメントすると、APIキーを設定せずにテストすることができませんでした。 –