我想找一个简单的方法来获取方向。有没有办法用mapview
执行此操作?
以下是我目前的代码。
- (IBAction)goToMap:(id)sender {
[self.view addSubview:self.mapUIView];
[self.mapUIView setFrame:CGRectMake(0, 0, 320, 460)];
self.mapview.mapType = MKMapTypeStandard;
CLLocationCoordinate2D coordinate;
coordinate.latitude = [[self.find lat] floatValue];
coordinate.longitude = [[self.find lng] floatValue];
MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
[annotation setCoordinate:coordinate];
[annotation setTitle:[self.find name]];
//[annotation setSubtitle:@"Hello"];
[self.mapview addAnnotation:annotation];
[annotation release];
[self zoomMapViewToFitAnnotations:self.mapview animated:YES];
}
答案 0 :(得分:0)
您无法将MapKit用于行车路线。它不支持这一点。
答案 1 :(得分:0)
如果你想显示设备的当前位置(比如在开车时),你必须在你的项目中添加CoreLocation框架,并且应该使用“updateLocation”方法来获取当前位置但是如果你想在两个位置之间绘制路径你必须使用谷歌Api。
答案 2 :(得分:0)
答案 3 :(得分:0)
CLLocationManager *manager = [[CLLocationManager alloc] init] ;
CLLocationCoordinate2D currentLocation = [manager location].coordinate;
CLLocationCoordinate2D coords = CLLocationCoordinate2DMake(37.365502,-94.394531);
NSString *fromLocation = [NSString stringWithFormat: @"%f,%f",
currentLocation.latitude, currentLocation.longitude];
NSString *toLocation = [NSString stringWithFormat: @"%f,%f",
Coordinate.latitude, Coordinate.longitude];
NSString *url = [NSString stringWithFormat:
@"http://maps.google.com/maps?saddr=%@&daddr=%@", fromLocation, fromLocation];
UIWebView *webView = [[UIWebView alloc]init];
NSURL *targetURL = [NSURL URLWithString:url];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];