0

私の質問に密接に関連するstackoverflowの他の質問を見てきましたが、私の問題は少し異なります。ここでは、コードはiPadで正常に機能しますが、iPhoneでは機能しません。私のiPadは300以上の注釈をすべて正しくロードしますが、iPhoneはそのうちの80個しかロードしません。これがiPhoneのメモリ量によるものかどうかはわかりません。これは、シミュレータでテストしたときに同じことを行うためです。以下に私のサンプルコードがあります。

@interface MOVmapViewController ()

@end

#define VA_LATITUDE 37.413754;
#define VA_LONGITUDE -79.142246;

//Span
#define THE_SPAN 5.50f;



@implementation MOVmapViewController
@synthesize myMapView;

-(IBAction)findmylocation:(id)sender {

    myMapView.showsUserLocation = YES;
    myMapView.delegate = MKMapTypeStandard;
    [myMapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES];

}

-(IBAction)setmaptype:(id)sender {

    switch (((UISegmentedControl *)sender).selectedSegmentIndex) {
        case 0:
            myMapView.mapType = MKMapTypeStandard;
            break;
        case 1:
            myMapView.mapType = MKMapTypeSatellite;
            break;
        case 2:
            myMapView.mapType = MKMapTypeHybrid;
            break;

        default:
            myMapView.mapType = MKMapTypeStandard;
            break;

    }

}


- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typiclly from a nib.

    //Create the region
    MKCoordinateRegion myRegion;

    //Center
    CLLocationCoordinate2D center;
    center.latitude = VA_LATITUDE;
    center.longitude = VA_LONGITUDE;

    //Span
    MKCoordinateSpan span;
    span.latitudeDelta = THE_SPAN;
    span.longitudeDelta = THE_SPAN;

    myRegion.center = center;
    myRegion.span = span;


    //Set our mapView
    [myMapView setRegion:myRegion animated:YES];

    //Annotations
    //Abingdon Lodge No. 48
    NSString *abingdon = @"325 W Main Street Abingdon, Virginia 24210";
    CLGeocoder *abingdongeo = [[CLGeocoder alloc] init];
    [abingdongeo geocodeAddressString:abingdon completionHandler:^(NSArray* placemarks, NSError* error){
        if (placemarks && placemarks.count > 0) {CLPlacemark *topResult = [placemarks objectAtIndex:0];
            MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:topResult];
            MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
            point.coordinate = placemark.coordinate;
            point.title = @"Abingdon Lodge No. 48";
            point.subtitle = @"Abingdon, VA";
            [self.myMapView addAnnotation:point]; }}];


    //York Lodge No. 12
    NSString *york = @"14411 Black Hollow Road Abingdon, Virginia 24210";
    CLGeocoder *yorkgeo = [[CLGeocoder alloc] init];
    [yorkgeo geocodeAddressString:york completionHandler:^(NSArray* placemarks, NSError* error){
        if (placemarks && placemarks.count > 0) {CLPlacemark *topResult = [placemarks objectAtIndex:0];
            MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:topResult];
            MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
            point.coordinate = placemark.coordinate;
            point.title = @"York Lodge No. 12";
            point.subtitle = @"Abingdon, VA";
            [self.myMapView addAnnotation:point]; }}];

    //Alberene Lodge No. 277
    NSString *alberene = @"2722 Plank Road Alberene, Virginia 22959";
    CLGeocoder *alberenegeo = [[CLGeocoder alloc] init];
    [alberenegeo geocodeAddressString:alberene completionHandler:^(NSArray* placemarks, NSError* error){
        if (placemarks && placemarks.count > 0) {CLPlacemark *topResult = [placemarks objectAtIndex:0];
            MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:topResult];
            MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
            point.coordinate = placemark.coordinate;
            point.title = @"Alberene Lodge No. 277";
            point.subtitle = @"Alberene, VA";
            [self.myMapView addAnnotation:point]; }}];


    //A. Douglas Smith, Jr. Lodge of Research No. 1949
    NSString *douglas = @"101 Callahan Drive Alexandria, Virginia 22301";
    CLGeocoder *douglasgeo = [[CLGeocoder alloc] init];
    [douglasgeo geocodeAddressString:douglas completionHandler:^(NSArray* placemarks, NSError* error){
        if (placemarks && placemarks.count > 0) {CLPlacemark *topResult = [placemarks objectAtIndex:0];
            MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:topResult];
            MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
            point.coordinate = placemark.coordinate;
            point.title = @"A. Douglas Smith, Jr. Lodge of Research No. 1949";
            point.subtitle = @"Alexandria, VA";
            [self.myMapView addAnnotation:point]; }}];

    //Alexandria-Washington Lodge No. 22 same location as above use lat/long
    CLLocationCoordinate2D washington;
    washington.latitude = 38.806758;
    washington.longitude = -77.065251;
    Annotation *alexandriawashingtonlodge = [Annotation alloc];
    alexandriawashingtonlodge.coordinate = washington;
    alexandriawashingtonlodge.title = @"Alexandria-Washington Lodge No. 22";
    alexandriawashingtonlodge.subtitle = @"Alexandria, VA";
    [self.myMapView addAnnotation:alexandriawashingtonlodge];

このリストは、合計約310のロッジの場所に続きます。

4

2 に答える 2

1

このように使用して、

NSString *abingdon = @"325 W Main Street Abingdon, Virginia 24210";
CLGeocoder *abingdongeo = [[CLGeocoder alloc] init];
[abingdongeo geocodeAddressString:abingdon completionHandler:^(NSArray* placemarks, NSError* error){
if (placemarks && placemarks.count > 0) {
CLPlacemark *topResult = [placemarks objectAtIndex:0];
MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:topResult];
MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
point.coordinate = placemark.coordinate;
point.title = @"Abingdon Lodge No. 48";
point.subtitle = @"Abingdon, VA";

// Set your region using placemark (not point)          
MKCoordinateRegion region = self.mapView.region;
region.center = placemark.region.center;
region.span.longitudeDelta /= 8.0;
region.span.latitudeDelta /= 8.0;

// Add point (not placemark) to the mapView                                              
[self.mapView setRegion:region animated:YES];
[self.mapView addAnnotation:point];

// Select the PointAnnotation programatically
[self.mapView selectAnnotation:point animated:NO]; }}];
于 2012-12-06T06:15:24.890 に答える
0

一部のアノテーションが表示されないのは、CLGeocoderを何度も呼び出しているためです。これが私が問題を修正した方法です。

//Columbia Lodge No. 285 CLLocationCoordinate2D columbia; columbia.latitude = 38.895746; columbia.longitude = -77.106511; Annotation *columbialodge = [[Annotation alloc] init]; columbialodge.coordinate = columbia; columbialodge.title = @"Columbia Lodge No. 285"; columbialodge.subtitle = @"Arlington, VA"; [self.myMapView addAnnotation:columbialodge];

住所をすべてLatlongに変換しました。これにより、メモリ使用量も削減されました。

アドレスを入力するだけで楽しんだのと同じくらい、CLGeocoderは多くのリソースを使用しているように見えます。

于 2012-12-09T14:48:25.023 に答える