【发布时间】:2012-03-26 09:10:41
【问题描述】:
我有一个应用程序非常成功地使用了 Apple 地图:我有一个包含一些兴趣点的列表,如果我先点击其中一个,应用程序会在地图上显示它,然后,如果我点击它,它会打开 Apple 地图应用导航。
问题是,在第一次点击/启动时,应用程序会打开 Apple Maps,但无论是否请求使用用户位置的权限,Apple Maps 都不起作用并返回:“Directions Not Available . 在这些位置之间找不到方向。”但在 General Setting 中,我的应用的位置服务设置为 ON。
我认为我必须使用某种超时,因为我的应用程序需要很长时间来解析导航数据(我从 xml 检索数据)但在第二次点击时一切正常,即使我从 Mac 中运行它调试模式(甚至第二次解析xml)...
我希望我解释得很好。有什么提示吗?
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *pinView = nil;
if(annotation != mapView.userLocation)
{
static NSString *defaultPinID = @"com.invasivecode.pin";
pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinView == nil ) pinView = [[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
pinView.pinColor = MKPinAnnotationColorRed;
UIButton *myAccessoryButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 24, 24)];
[myAccessoryButton setBackgroundColor:[UIColor clearColor]];
[myAccessoryButton setImage:[UIImage imageNamed:@"flag.png"] forState:UIControlStateNormal];
pinView.rightCalloutAccessoryView = myAccessoryButton;
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
[myAccessoryButton release];
}
else {
[mapView.userLocation setTitle:@"You're here"];
}
return pinView;
}
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
CLLocation *location = [locationManager location];
// Configure the new event with information from the location
CLLocationCoordinate2D coordinate = [location coordinate];
NSString *latitude = [NSString stringWithFormat:@"%f", coordinate.latitude];
NSString *longitude = [NSString stringWithFormat:@"%f", coordinate.longitude];
CLLocationCoordinate2D start = { [latitude floatValue], [longitude floatValue] };
CLLocationCoordinate2D end = {[posto.latitude floatValue], [posto.longitude floatValue]};
NSString *googleMapsURLString = [NSString stringWithFormat:@"http://maps.google.com/?saddr=%1.6f,%1.6f&daddr=%1.6f,%1.6f", start.latitude, start.longitude, end.latitude, end.longitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:googleMapsURLString]];
}
【问题讨论】:
标签: ios google-maps core-location