I can't show a web map using AGSWebMap

2515
7
Jump to solution
08-11-2014 11:31 PM
DouglasBocking
New Contributor

I'm trying to show an online map using AGSWebMap and I'm not sure where I'm going wrong.

This is my code: ViewController.h

#import <UIKit/UIKit.h>

#import <ArcGIS/ArcGIS.h>

@interface ViewController : UIViewController <AGSWebMapDelegate>

@property (strong, nonatomic) IBOutlet AGSMapView *mapView;

@property (retain, nonatomic) AGSWebMap *webmap;

@end

This is my code: ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

@synthesize mapView;

@synthesize webmap;

- (void)viewDidLoad{

    [super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

   

#pragma mark -

   

- (void) openIntoMapView: (AGSMapView*) mapView {

        self.webmap = [[AGSWebMap alloc] initWithItemId:@"7acfdd8e056240bfaa5ba46db7cdae7d" credential:nil];

        self.webmap.delegate = self;

    }

    - (void)webMapDidLoad:(AGSWebMap *)webmap {

       

        NSLog(@"delegate webMapDidLoad");

        //open webmap in mapview

        [self.webmap openIntoMapView:self.mapView];

    }

   

    -(void)didOpenWebMap:(AGSWebMap*)webmap intoMapView:(AGSMapView*)mapView {

        NSLog(@"delegate didOpenWebMap");

    }

   

    - (void)dealloc {

        [mapView release];

        [super dealloc];

    }

    - (void)viewDidUnload {

        [self setMapView:nil]; 

        [super viewDidUnload]; 

    }

}

- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

@end

I keep getting an error on line 19. Saying "use of undeclared identifier 'openIntoMapView'".

could anyone help me out here. Its a public webmap so doesn't need any credentials.

0 Kudos
1 Solution

Accepted Solutions
TomBruns
Esri Contributor

I think it is a simple error, but still a compiler error. If the code you posted is still the code you are trying to compile, the error you are seeing makes sense. Take a closer look. Or, if you like, attach your project, or put it in a public repo on github, and I'll tweak the code so you can see where the error is.

Here is a simplified version of your viewcontroller, to illustrate.

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad

{

    [super viewDidLoad];

    self.webmap = [[AGSWebMap alloc] initWithItemId:@"7acfdd8e056240bfaa5ba46db7cdae7d" credential:nil];

    self.webmap.delegate = self;

}

- (void)webMapDidLoad:(AGSWebMap *)webmap

{

    [self.webmap openIntoMapView:self.mapView];

}

@end

In viewDidLoad the webmap is created and its delegate assigned. When the webmap loads it calls the delegate method webMapDidLoad, at which point the webmap is opened in the map view.

I've moved the opening curly-brace of each method to a separate line. This may not be the preferred style, but I think it helps clarify these sorts of compiler errors caused by an imbalance or misplacement of braces.

View solution in original post

7 Replies
TomBruns
Esri Contributor

Looks like the code isn't correctly formatted, like some code was incorrectly pasted into viewDidLoad. Look at the curly braces, there should be a "}" at line 16 before the function openIntoMapView. I see a couple other similar issues.

I suggest taking a look at the SDK sample on opening a web map: Viewing a web map—ArcGIS Runtime SDK for iOS | ArcGIS for Developers

Follow the link to a sample project on github.

0 Kudos
DouglasBocking
New Contributor

Thanks @Tom Bruns for your help here . I have been to these links before seeking help and have had no luck in solving my current problem I'm having here . I've been trying to learn off a question that someone asked having a similar problem as mine. This is the link : https://community.esri.com/message/43416#43416

It seems that they were able to show a webMap and solve their problem. The code I am using is exactly the same as  Sobodh Dangwal's though I have fixed the error where he left out  "- (void)viewDidLoad {". Yet when I try it I keep getting the error "use of undeclared identifier 'openIntoMapView' "

I have a feeling it is a very simple error that I am making. There must be someone out there that can help me out.

0 Kudos
TomBruns
Esri Contributor

I think it is a simple error, but still a compiler error. If the code you posted is still the code you are trying to compile, the error you are seeing makes sense. Take a closer look. Or, if you like, attach your project, or put it in a public repo on github, and I'll tweak the code so you can see where the error is.

Here is a simplified version of your viewcontroller, to illustrate.

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad

{

    [super viewDidLoad];

    self.webmap = [[AGSWebMap alloc] initWithItemId:@"7acfdd8e056240bfaa5ba46db7cdae7d" credential:nil];

    self.webmap.delegate = self;

}

- (void)webMapDidLoad:(AGSWebMap *)webmap

{

    [self.webmap openIntoMapView:self.mapView];

}

@end

In viewDidLoad the webmap is created and its delegate assigned. When the webmap loads it calls the delegate method webMapDidLoad, at which point the webmap is opened in the map view.

I've moved the opening curly-brace of each method to a separate line. This may not be the preferred style, but I think it helps clarify these sorts of compiler errors caused by an imbalance or misplacement of braces.

DouglasBocking
New Contributor

Thank you so much Tom!!! it worked!! I'll attach my project here so that you can tweek it to show me where i went wrong in the larger code so i can learn from that. If that's ok with you?

0 Kudos
TomBruns
Esri Contributor

Ok with me

0 Kudos
GagandeepSingh
Occasional Contributor II

Hi Douglas Bocking‌,

I did a chance to look at your project and as Tom Bruns‌ mentioned, there is a curly brace missing for the `viewDidLoad` method closure, and that is what is causing the error.

Also, if you are using Automatic Reference Counting (ARC), you don't need to explicitly release objects.

I hope this helps!

Gagan

TomBruns
Esri Contributor

Hey Douglas Bocking‌, finally took a look at your code. I agree with Gagandeep Singh‌. With some minor fixes your project works, and I hope you understand how the pieces fit together and that you continue to work on your app.