我在MapKit一個新手的iPhone,並試圖實現這一點,出於某種原因,我不能看到當前位置的藍色小點,其他人有這個問題????MapKit不顯示藍點的當前位置
#import "DetailMapViewController.h"
#import "mapAnnotations.h"
@implementation DetailMapViewController
@synthesize inStock;
-(void)getlocation:(CLLocationCoordinate2D)loc
{
location = loc;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.title = @"Street View";
mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];
mapView.delegate=self;
//MKCoordinateRegion region;
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(location, 5000, 5000);
mapAnnotations *ann = [[mapAnnotations alloc] init];
ann.title = @"";
ann.subtitle = @"";
ann.coordinate = region.center;
mapView.showsUserLocation = YES;
[mapView addAnnotation:ann];
[mapView setRegion:region animated:TRUE];
[mapView regionThatFits:region];
[self.view insertSubview:mapView atIndex:0];
}
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
if (annotation == mapView.userLocation)
{
annView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"blueDot"];
if (annView != nil)
{
annView.annotation = annotation;
}
else
{
annView = [[[NSClassFromString(@"MKUserLocationView") alloc] initWithAnnotation:annotation reuseIdentifier:@"blueDot"] autorelease];
}
}
if([inStock isEqual:@"yes"]){
annView.pinColor = MKPinAnnotationColorGreen;
}
if([inStock isEqual:@"no"]){
annView.pinColor = MKPinAnnotationColorRed;
}
if([inStock isEqual:@"unknown"]){
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"greyPin.png"]];
[annView addSubview:imageView];
}
annView.animatesDrop=TRUE;
annView.canShowCallout = YES;
annView.calloutOffset = CGPointMake(-5, 5);
return annView;
}
- (void)dealloc {
[super dealloc];
}
@end
我看到你有showsUserLocation =是的,這應該做的伎倆,除非你沒有連接XIB文件到mapview控制到控制器? – pdiddy 2010-10-29 21:23:35
你確保你的當前位置是上面'location'5000米內? – bosmacs 2010-10-29 21:26:43
我AVE不能保證我在5000米 - 我從來沒有使用過XIB文件。 – vivianaranha 2010-10-29 21:30:04