Select to view content in your preferred language

Draw using GPS position

1139
3
01-28-2013 11:51 AM
VIKRANTKRISHNA
Regular Contributor
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
0 Kudos
3 Replies
DiveshGoyal
Esri Regular Contributor
Have you taken a look at the GPS sketching sample
0 Kudos
VIKRANTKRISHNA
Regular Contributor
I am having some trouble in running GPS Sketch sample on my mac. Although , I found this http://stackoverflow.com/questions/11791888/arcgis-current-location , seems to be working better , but I am still getting some weird drawing when drawing Line .

I will post back once I get the GPS sample working.

Thanks,
0 Kudos
DanaMaher
Regular Contributor


...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


I am about 100% certain this is a projection issue; your returned gps points are provided in a different spatial reference than the map is using. For case 1), the gps point is in the wrong spatial reference and therefor draws somewhere outside the extent of the map and is never seen. For case 2), the first two vertices are in the correct spatial reference, but the added gps vertex is not and so the line draws off to wherever the point is outside the coordinate system / spatial reference the map is using. Check the AGSSpatialReference of the AGSPoints points you are getting back from the gps against that of the AGSMapView.

I'm pretty sure that gps points or user tap points from AGSMapView are always returned in wgs84 / wkid 4326. If the first layer you added to the AGSMapView is an AGSTiledMapServiceLayer in the popular web mercator / wkid 102100 projection, your AGSMapView will use web mercator as its spatial reference. That mismatch would create this behavior; geometries are not currently reprojected on the fly by the Runtime SDK.

I posted some sample code in this thread about a different issue arising from spatial reference mismatches. It shows the basics of checking spatial references against each other and reprojecting using AGSGeometryEngine.
0 Kudos