AGSPoints / AGSGraphics displaying at 0,0

Discussion created by pml on Aug 31, 2011
Latest reply on Oct 7, 2011 by pml
Xcode 3.2
iOS SDK 4.2
ArcGIS for iOS SDK 2.0

I have lines in a comma-separated text file that I am reading into AGSPoints then putting the AGSPoints into AGSGraphics. The lines contain X and Y values. I push each AGSGraphic into an AGSGraphicsLayer. The problem is the AGSGraphic items are displaying at 0,0 on the map. Stepping through the code, the correct X and Y values are in myGraphicArray and are in myGraphicsLayer. Here is the code. Thank you for any help.


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

@interface MapView : UIViewController {
    AGSMapView *_mapView;
    AGSSimpleMarkerSymbol *myMarkerSymbol;
    AGSGraphicsLayer *myGraphicsLayer;

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

- (void)loadPointsOnMap;



#import "MapView.h"
#import "GPS1AppDelegate.h"
#import "TextFileMgmt.h"

@implementation MapView

@synthesize mapView = _mapView;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        myMarkerSymbol = [[AGSSimpleMarkerSymbol alloc] init];
        myMarkerSymbol = [AGSSimpleMarkerSymbol simpleMarkerSymbol];
        myMarkerSymbol.color = [UIColor blueColor];
  // create a graphics layer
  myGraphicsLayer = [[AGSGraphicsLayer alloc] init];
  myGraphicsLayer = [AGSGraphicsLayer graphicsLayer];
    return self;

- (void)didReceiveMemoryWarning
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.

#pragma mark - View lifecycle

    // get extent of points in current file including user's location
    // zoom to the new extent
    [super viewDidLoad];
    AGSTiledMapServiceLayer *tiledLayer = [[AGSTiledMapServiceLayer alloc] 
                                           initWithURL:[NSURL URLWithString:@""]];
    [self.mapView addMapLayer:tiledLayer withName:@"Aerial Basemap"];
    [tiledLayer release];
    NSLog(@"mapView: %@", self.mapView.spatialReference);
    // call local method to place points on map.
    [self loadPointsOnMap];

- (void)viewDidUnload
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);

    // alloc and init an instance of the TextFileMgmt class.
    TextFileMgmt *textFileMgmt1 = [[TextFileMgmt alloc] init];
    // run the parseTextFile method.
    [textFileMgmt1 parseTextFile];
    // now the points array should be filled with dictionary entries.
    // feed each point into an AGSPoint object array.
    NSMutableArray *myMarkerPointArray = [[NSMutableArray alloc] init];
    NSLog(@"textFileMgmt1 dict_x_long = %@", [textFileMgmt1.points valueForKey:@"dict_x_long"]);
    for ( NSDictionary *item in textFileMgmt1.points )
            AGSPoint *myPoint = [[AGSPoint alloc] init];
            myPoint = [AGSPoint pointWithX:[[item valueForKey:@"dict_x_long"] doubleValue]
                                         y:[[item valueForKey:@"dict_y_lat"] doubleValue]
            [myMarkerPointArray addObject:myPoint];
            [myPoint release];
    NSLog(@"myMarkerPointArray contains: %@", myMarkerPointArray);
    // once this for loop completes, we have an NSMutableArray holding AGSPoint instances.
    // feed each AGSPoint from the myMarkerPoint array into an AGSGraphic object array.
    NSMutableArray *myGraphicArray = [[NSMutableArray alloc] init];
    for ( AGSPoint *item in myMarkerPointArray )
            AGSGraphic *myGraphic = [[AGSGraphic alloc] init];
            myGraphic = [AGSGraphic graphicWithGeometry:item 
            [myGraphicArray addObject:myGraphic];
            [myGraphic release];
    NSLog(@"myGraphicArray contains: %@", myGraphicArray);
    // once this for loop completes, we have an array of AGSGraphic instances.
    // send the AGSGraphic array to an AGSGraphicsLayer.
    for ( AGSGraphic *item in myGraphicArray )
            NSLog(@"item contains: %@", item);
            // myGraphicsLayer was created in the init method.
            [myGraphicsLayer addGraphic:item];
    // our content should be ready for the map so add the layer.
    NSLog(@"myGraphicsLayer: %@", myGraphicsLayer);
    [self.mapView addMapLayer:myGraphicsLayer withName:@"Graphics Layer"];
    [myGraphicsLayer dataChanged];
    [myGraphicsLayer release];

- (void)dealloc 
    self.mapView = nil;
    [super dealloc];