GeometryEngine.project - YUNOwork? ^^

2184
2
03-04-2013 09:19 PM
AxelBronder1
New Contributor
Hey guys,

can´t seem to be able to project my GPS coordinated from Google maps to map coordinates. What am I doing wrong?

here le code:

Point wgspnt = new Point();
wgspnt.setXY(-29.34016, 27.466609);
//Google maps: We use EPSG:4326 (WGS 84) for coordinates (Lat/Long). The projection we use is Mercator (EPSG:3857)
  
Log.i(TAG, "wgsLatBEFORE=" + wgspnt.getX()); //wgsLatBEFORE=-29.34016
  
Point mapPoint = (Point) GeometryEngine.project(wgspnt, SpatialReference.create(4326), mMapView.getSpatialReference()); 
//have also tried from 3857, with the same result
  
Log.i(TAG, "wgsLatAFTER=" + mapPoint.getX()); //wgsLatBEFORE=-29.34016 (STILL!)
  
Graphic poi1 = new Graphic(mapPoint, marker);
gLayer.addGraphic(poi1);
mMapView.addLayer(gLayer);


To me, GeometryEngine.project seem to do nothing here and the point ends up close to 0.0 instead of in Lesotho.
I am also displaying a point in Switzerland that ends up in the right place: Point chPoint = new Point (947296, 6008979); so thats the type of coordinates I want to project into.
0 Kudos
2 Replies
AxelBronder1
New Contributor
Update:

I found out that I can project my location to the right coordinates, but no luck in projecting the manually inserted point :S

this works: (but the code I posted above doesn't...)

double locy = loc.getLatitude();
double locx = loc.getLongitude();
        
System.out.println("Pos before"+locx); // 27.4661603
        
Point wgspoint = new Point(locx, locy);
Point mapPoint = (Point) GeometryEngine
   .project(wgspoint,
   SpatialReference.create(4326),
mMapView.getSpatialReference());
        
System.out.println("Pos after"+mapPoint.getX()); //3057518.978642426
0 Kudos
AxelBronder1
New Contributor
Solved;

turns out the graphicalLayer gets drawn before the mapsurface spatial reference is initialized.

Point mapPointNew = (Point) GeometryEngine.project(wgspnt, SpatialReference.create(4326), SpatialReference.create(3857));


finally did the trick... thought I had tried this already...
0 Kudos