vikrant327

Draw using GPS position

Discussion created by vikrant327 on Jan 28, 2013
Latest reply on Feb 6, 2013 by bernese
I am trying to create a similar GPS workflow as in ArcGIS Online iOS Application. Basically I have a GPS button and a add point button, when GPS button is on, map shows GPS poisition and tap on satellite button adds a point on the map and this part works fine for me. Next, if user taps add point button the what it should do is

1) Take you GPS location
2) Add point then

Action code for Add Point is

self.sketLayer.geometry =  Mutable Type........
is set to point,line or polygon based on user selection in different method

  - (IBAction)addGPSPoint:(id)sender{  
    if(!self.mapView.gps.enabled){
        [self.mapView.gps start];
        self.mapView.gps.autoPanMode = AGSGPSAutoPanModeDefault;
        self.mapView.gps.wanderExtentFactor = 0.75;
        self.mapView.gps.navigationPointHeightFactor = 0.8;
        UIImage *gpsImg2 = [UIImage imageNamed:@"onGPS.png"];
        [self.gpsButton setBackgroundImage:gpsImg2 forState:UIControlStateNormal];
        
    }
    AGSPoint *gpsPoint = [self.mapView.gps currentPoint];
    AGSSpatialReference *sr = [AGSSpatialReference spatialReferenceWithWKID:26915];
    if([self.sketchLayer.geometry isKindOfClass:[AGSMutablePolyline class]]){
            [self.sketchLayer.geometry addPointToPath:[AGSPoint pointWithX:gpsPoint.x y:gpsPoint.y spatialReference:sr]];
    }
    else if([self.sketchLayer.geometry isKindOfClass:[AGSMutablePolygon class]]){
        [self.sketchLayer.geometry addPointToRing:[AGSPoint pointWithX:gpsPoint.x y:gpsPoint.y spatialReference:sr]];
        
    }
    else{
        self.sketchLayer.geometry = [AGSPoint pointWithX:gpsPoint.x y:gpsPoint.y spatialReference:sr];
    }
    NSLog(@"%@",self.sketchLayer.geometry);
    [self.sketchLayer dataChanged];


}





whats happening is that
1) point doesn't get added if sketch geometry is currently empty (i.e. adding first vertex of geometry using GPS)
2) If suppose there are already a line with 2 vertices on the map and I try to add third point using GPS, Line goes somewhere outside the map area to unknown vertex.

Is there anyone who known how to implement this correctly?

Thanks,
Vik

Outcomes