I can't show a web map using AGSWebMap

1534
10
12-19-2011 06:58 AM
JoseMorales
New Contributor
I am trying to show a online map using AGSWebMap but I don't know exactly how doing.

This is my code: ViewController.h
#import <UIKit/UIKit.h>
#import "ArcGis.h"

@interface ViewController : UIViewController 
@property (retain, nonatomic) IBOutlet AGSMapView *mapView;
    
@end


ViewController.m
#import "ViewController.h"

@implementation ViewController
@synthesize mapView;
.....

- (void) openIntoMapView: (AGSMapView*) mapView {
    AGSCredential* credential = [[[AGSCredential alloc] initWithUser:@"<my_user_name>" password:@"<My_passdword>"] autorelease];
    credential.authType = AGSAuthenticationTypeToken;
    AGSWebMap* webmap = [[AGSWebMap alloc] initWithItemId:@"e20f2f98b35c4963a5e124bf43c1d74a" credential:credential];
}



I received a message from Xcode "Unusued variable webmap" and the simulator show a white screen. Could anyone help me to solve this error? Thanks
0 Kudos
10 Replies
NimeshJarecha
Esri Regular Contributor
Just add a code line...

    AGSCredential* credential = [[[AGSCredential alloc] initWithUser:@"<my_user_name>" password:@"<My_passdword>"] autorelease];
    credential.authType = AGSAuthenticationTypeToken;
    AGSWebMap* webmap = [[AGSWebMap alloc] initWithItemId:@"e20f2f98b35c4963a5e124bf43c1d74a" credential:credential];
[webmap openIntoMapView:self.mapView]; //added


Regards,
Nimesh
0 Kudos
SobodhDangwal
New Contributor III
Just add a code line...

    AGSCredential* credential = [[[AGSCredential alloc] initWithUser:@"<my_user_name>" password:@"<My_passdword>"] autorelease];
    credential.authType = AGSAuthenticationTypeToken;
    AGSWebMap* webmap = [[AGSWebMap alloc] initWithItemId:@"e20f2f98b35c4963a5e124bf43c1d74a" credential:credential];
[webmap openIntoMapView:self.mapView]; //added


Regards,
Nimesh


Hi Nimesh

I am having the same problem and getting a white screen, even though I have added the above bit you suggested.

Here is my code

- (void) openIntoMapView: (AGSMapView*) mapView {
   
    AGSWebMap* webmap = [[AGSWebMap alloc] initWithItemId:@"3e7c311a0f2c49a1a5821411a22e3ac2" ];
[webmap openIntoMapView:self.mapView];
}

Its a public webmap so doesn't need any credentials. In my case it throws a warning as 'Method -initWithItemId not found' . I have included #import "ArcGIS.h" file properly.

Any help will be appreciated. Also it would be nice to have a sample created to display ArcGIS.com WebMap using iOS.

Cheers
0 Kudos
NimeshJarecha
Esri Regular Contributor
Okie..i know what's happening. You must retain webmap so the instance remain around until web map finish loading and then you can open into mapView. Here is the code you should try..

ViewController.h

#import <UIKit/UIKit.h>
#import "ArcGis.h"

@interface <Classname> : UIViewController <AGSWebMapDelegate>

@interface ViewController : UIViewController 
@property (retain, nonatomic) IBOutlet AGSMapView *mapView;
@property (retain, nonatomic) AGSWebmap *webmap;
    
@end


ViewController.m

- (void)viewDidLoad {
    AGSCredential* credential = [[[AGSCredential alloc] initWithUser:@"<my_user_name>" password:@"<My_passdword>"] autorelease];
    credential.authType = AGSAuthenticationTypeToken;
    self.webmap = [[AGSWebMap alloc] initWithItemId:@"e20f2f98b35c4963a5e124bf43c1d74a" credential:credential];
    self.webmap.delegate = self
}

#pragma mark AGSWebMapDelegate

- (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");
}


Even though, the web map is public you must use the complete method..

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

Regards,
Nimesh
0 Kudos
JoseMorales
New Contributor
I tried your code and the white screen appear newly. Xcode says that there is no error in the code.

ViewController.h

#import <UIKit/UIKit.h>
#import "ArcGis.h"

@interface ViewController : UIViewController <AGSWebMapDelegate>
@property (retain, nonatomic) IBOutlet AGSMapView *mapView;
@property (retain, nonatomic) AGSWebMap *webmap;

@end


ViewController.m

#import "ViewController.h"

@implementation ViewController
@synthesize mapView;
@synthesize webmap;


#pragma mark - 

- (void) openIntoMapView: (AGSMapView*) mapView {
    self.webmap = [[AGSWebMap alloc] initWithItemId:@"d802f08316e84c6592ef681c50178f17" 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];
}
@end
0 Kudos
NimeshJarecha
Esri Regular Contributor
Do you see anything printed on the debug window for following NSLog statements?

NSLog(@"delegate webMapDidLoad");
NSLog(@"delegate didOpenWebMap");

Regards,
Nimesh
0 Kudos
JoseMorales
New Contributor
The console printed this information:

GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Mon Aug  8 20:32:45 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".
sharedlibrary apply-load-rules all
Attaching to process 16588.
Couldn't register c.webMap with the bootstrap server. Error: unknown error code.
This generally means that another instance of this process was already running or is hung in the debugger.Current language:  auto; currently objective-c
(gdb) 
0 Kudos
NimeshJarecha
Esri Regular Contributor
Looks like something wrong with the simulator. Please restart your machine and then try...

Regards,
Nimesh
0 Kudos
JoseMorales
New Contributor
After restart my computer this is de console message:
GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Mon Aug  8 20:32:45 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".
sharedlibrary apply-load-rules all
Attaching to process 505.


... and the map follow without appear only a white screen. Any ideas???

I attach the project.
0 Kudos
NimeshJarecha
Esri Regular Contributor
The code written by you never executes. Because the first method which view executes is viewDidLoad and it's missing. 😞

Just change the code as below and it should work..

//- (void) openIntoMapView: (AGSMapView*) mapView {
- (void)viewDidLoad {
    self.webmap = [[AGSWebMap alloc] initWithItemId:@"d802f08316e84c6592ef681c50178f17" credential:nil];
    self.webmap.delegate = self;
}


Regards,
Nimesh
0 Kudos