I can take a geolocation event and add a graphic to the map and recenter the map on the graphic. I would like to reproject the graphic to a state plane coordinate system and have reviewed samples and past threads and cannot seem to get it to work. I have an if else statement so i can just change the map services to see if the point is reprojecting, it works great on a WGS 84 projection. When i change the map service to a state plane it puts the graphic at some crazy coordiantes. Not sure what i am going wrong, any help would be appreciated private function onTravel(event:GeolocationEvent):void
{
if (GPSCheck.selected==true)
{
var long:String = event.longitude.toString();
var lat:String = event.latitude.toString();
var longnew:Number = Number(long);
var latnew:Number = Number(lat);
if (map.spatialReference.wkid == 4326)
{
var centerPoint:MapPoint = new MapPoint(longnew, latnew);
var graphic:Graphic = new Graphic();
graphic.geometry = centerPoint;
myGraphicsLayer.clear();
myGraphicsLayer.add(graphic);
}
else
{
var centerPoint1:MapPoint = new MapPoint(longnew, latnew);
var outSR:SpatialReference = new SpatialReference(2234);
geometryService.project([centerPoint1 as Geometry], outSR);
var ptGraphic:Graphic = new Graphic();
var mapPoint2:MapPoint = centerPoint1;
mapPoint2.spatialReference = map.spatialReference;
ptGraphic.geometry = mapPoint2;
myGraphicsLayer.clear()
myGraphicsLayer.add(ptGraphic);
ptGraphic.addEventListener(GeometryServiceEvent.PROJECT_COMPLETE, projectCompleteHandler);
}
}
else
{
geolocation.removeEventListener(GeolocationEvent.UPDATE, onTravel);
}
}
private function projectCompleteHandler(event:GeometryServiceEvent):void
{
// Note: As of version 2.0, GeometryService returns geometries (instead of graphics)
var pt:MapPoint = (event.result as Array)[0]as MapPoint;
}