试图获得与iOS项目集成的当前位置

问题描述:

所以我试图将用户的当前位置与我的iOS项目集成 - 我使用第三部分代码构建出具有pinpoint的地图 - 我集成了这些框架:试图获得与iOS项目集成的当前位置

#import <UIKit/UIKit.h> 
#import <CoreLocation/CoreLocation.h> 
#import <QuartzCore/QuartzCore.h> 
#import <MapKit/MapKit.h> 

这里是我的代码与精确定位 - 任何帮助将不胜感激:

#import "asyMap.h" 

@implementation asyMap 
@synthesize currentAnnotation,mapAnnotations,map,prompt,mapFromLink,selectedAnnotationId,selectedAnnotationIndex,showOthers,useCustomTitle,customTitle; 
/** 
* Class constructor 
*/ 
-(id)init{ 
    self = [super init]; 
    if(self){ 
     useCustomTitle = FALSE; 
     mapFromLink = FALSE; 
     showOthers = FALSE; 
     map = [[asyMapObject alloc] init]; 
     [map addOnView:self.view]; 
    }  
    return self; 
} 

/** 
* Overwrite the set page method in 
* order to show a selected annotation 
* from a link 
*/ 
-(void)setPage:(NSDictionary *)page{ 
    NSDictionary *metas = [page valueForKey:@"metas"]; 
    if([metas valueForKey:@"selectedAnnotationPageTitle"] && ![[[metas valueForKey:@"selectedAnnotationPageTitle"] stringValue] isEqualToString:@""] && customTitle == nil){ 
     useCustomTitle = TRUE; 
     NSString *newTitle = [metas valueForKey:@"selectedAnnotationPageTitle"]; 
     customTitle = [[NSString alloc] initWithString:[[newTitle stringByReplacingOccurrencesOfString:@"+" withString:@" "] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 

    } 
    if(useCustomTitle && customTitle != nil){ 
     NSMutableDictionary *pageWithCustomTitle = [[NSMutableDictionary alloc] initWithDictionary:page]; 
     [pageWithCustomTitle setValue:customTitle forKey:@"title"]; 
     [super 
     setPage:pageWithCustomTitle]; 
    }else{ 
     [super setPage:page]; 
    } 
    if([metas valueForKey:@"annotationFromLink"] && [[[metas valueForKey:@"annotationFromLink"] stringValue] isEqualToString:@"yes"] && selectedAnnotationId == nil){ 
     selectedAnnotationId = [[NSString alloc] initWithString:[metas valueForKey:@"selectedAnnotation"]]; 
     mapFromLink = TRUE; 
     showOthers = [[[metas valueForKey:@"showOthers"] stringValue] isEqualToString:@"yes"]; 
    }else if(mapFromLink && selectedAnnotationId != nil){ 
     mapFromLink = FALSE; 
     NSArray *annotations = [page valueForKey:@"annotations"]; 
     for(int a = 0; a < [annotations count]; a++){ 
      NSDictionary *annotation = [annotations objectAtIndex:a]; 
      if([[[annotation valueForKey:@"annotationId"] stringValue] isEqualToString:selectedAnnotationId]){ 
       mapFromLink = TRUE; 
       selectedAnnotationIndex = a; 
       break; 
      } 
     } 
    } 
} 
/** 
* Set the module's name 
*/ 
-(void)makeProcess{ 
    [self setModuleName:@"map"]; 
} 
/** 
* Create the basic prompt alert 
*/ 
-(void)buildModule{ 
    prompt = [[UIAlertView alloc] initWithTitle:@"" message:[theme asy__:@"Open on the Maps app?"] delegate:self cancelButtonTitle:[theme asy__:@"No"] otherButtonTitles:[theme asy__:@"Yes"], nil]; 
} 
/** 
* Set the annotations after get the page data 
*/ 
-(void)requestedPage:(NSDictionary *)pageInformation{ 
    [self setPage:pageInformation]; 
    if(mapFromLink && !showOthers && [[self getPageMapAnnotations] count] > 0){ 
     NSArray *pageAnnotations = [self getPageMapAnnotations]; 
     mapAnnotations = [[NSArray alloc] initWithObjects:[pageAnnotations objectAtIndex:selectedAnnotationIndex],nil]; 
    }else{ 
     mapAnnotations = [[NSArray alloc] initWithArray:[self getPageMapAnnotations]]; 
    } 
    [map setMapAnnotations:mapAnnotations andDelegate:self]; 
    if(mapFromLink){ 
     [map focusMapOnAnnotationAtIndex:(showOthers ? selectedAnnotationIndex : 0)]; 
    } 
    [map build]; 
    [self hideLoading]; 
    [self checkPageOptionButton]; 
} 
/** 
* The module orientation did change 
*/ 
-(void)moduleOrientationDidChange{ 
    [map setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
} 

#pragma mark - Map Delegate 
/** 
* Check if the annotation has properties for action or the prompt to be opened 
* on the Maps app should appear 
*/ 
-(void)asyMapObject:(asyMapObject *)mapObject didSelectAnnotation:(NSDictionary *)annotation atIndex:(NSInteger)index{ 
    currentAnnotation = index; 
    if([[annotation valueForKey:@"menuId"] isEqualToString:@"0"] && 
     [[annotation valueForKey:@"pageId"] isEqualToString:@"0"] && 
     [[annotation valueForKey:@"link"] isEqualToString:@""] && 
     [[annotation valueForKey:@"url"] isEqualToString:@""] && 
     [[annotation valueForKey:@"phpfile"] isEqualToString:@""]){ 
     [prompt setTitle:[annotation valueForKey:@"title"]]; 
     [prompt show]; 
    }else{ 
     AppsifymeCore *core = [AppsifymeCore sharedAppsifymeCore]; 
     [core basicHandlerForMultiActionsOption:annotation]; 
    } 
} 

#pragma mark - Alert view delegate 
/** 
* Detect if the user wants to open the annotation on the maps app, and if its 
* true, this method build the link and open the app 
*/ 
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ 
    if(buttonIndex != 1) return; 
    AppsifymeCore *core = [AppsifymeCore sharedAppsifymeCore]; 
    NSDictionary *annotation = [mapAnnotations objectAtIndex:currentAnnotation]; 
    float latitude = [[annotation valueForKey:@"latitude"] floatValue]; 
    float longitude = [[annotation valueForKey:@"longitude"] floatValue]; 
    if(![core asyiOS6]){ 
     NSString *pinName = [[NSString alloc] initWithString:[core encodeURLParameter:[annotation valueForKey:@"title"]]]; 
     int zoom = 13; 
     NSString *stringURL = [[NSString alloc] initWithFormat:@"http://maps.apple.com/maps?q=%@@%1.6f,%1.6f&z=%d", pinName, latitude, longitude, zoom]; 
     NSURL *url = [[NSURL alloc] initWithString:stringURL]; 
     [[UIApplication sharedApplication] openURL:url]; 
    }else{ 
     Class itemClass = [MKMapItem class]; 
     if (itemClass && [itemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)]) { 
      CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude,longitude); 
      MKPlacemark *placeMark = [[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil]; 
      MKMapItem *item = [[MKMapItem alloc] initWithPlacemark:placeMark]; 
      item.name = [[annotation valueForKey:@"title"] stringValue]; 
      [item openInMapsWithLaunchOptions:nil]; 
     } 
    } 
} 


@end 

在你init方法,加入这一行

self.showsUserLocation = YES;