0
我想獲取mapkit中兩點之間的路線! ? 我做了一些谷歌的工作ñ發現這一點:-http://spitzkoff.com/craig/ P = 108查看地圖中兩點之間的路線+ iphone + Mapkit
我用這個來顯示地圖和引腳: -
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationController.navigationBarHidden=NO;
[email protected]"Map";
CLLocationCoordinate2D location;
location.latitude=[latLabel doubleValue];
location.longitude=[longLabel doubleValue];
MKCoordinateRegion region;// = MKCoordinateRegionMakeWithDistance(CLLocationCoordinate2DMake((location.latitude)/2.0, (location.longitude)/2.0), 1000.0, 1000.0);
region.center=location;
region.span.latitudeDelta =0.1;
region.span.longitudeDelta =0.1;
addAnnotation=[[AddressAnnotation alloc] initWithCoordinate:location];
NSLog(@"city=mapview=>%@",City);
NSLog(@"adress=mapview=>%@",Address);
addAnnotation.title=City;
addAnnotation.subtitle=Address;
[mapView addAnnotation:addAnnotation];
[mapView setRegion:region animated:YES];
}
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(AddressAnnotation *) annotation
{
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
annView.pinColor=MKPinAnnotationColorRed;
annView.draggable=TRUE;
annView.animatesDrop=TRUE;
annView.canShowCallout=YES;
annView.calloutOffset=CGPointMake(-5,5);
annView.draggable=TRUE;
return annView;
}
和註釋類來顯示名稱和地址。但我應該如何添加更多以顯示兩點之間的路線。
請幫幫我。
在此先感謝
嗨,謝謝你的解決方案!它對我很好,有一點細節......它崩潰了:P。在這一行上:CLLocation * location =(CLLocation *)[NSKeyedUnarchiver unarchiveObjectWithData:[routes objectAtIndex:i]]; 。錯誤日誌顯示「[CLLocation bytes]:發送到實例的無法識別的選擇器」。你有什麼想法可能是錯的?我得到谷歌的步驟列表,並有47個解碼點在我的數組,但這unarchiveObjectWithData調用使應用程序崩潰。請讓我知道你是否知道爲什麼。再次感謝您的解決方案。問候,喬治 – George
@喬治的unarchiving是可能存在的,因爲我必須早先存檔數據。如果你直接使用,你不會需要。 –