Okay, makes sense. So I did that, but I still get the same print statements (just a bit later than when they are outside the function) :
Conversion completed
Latitude : *correct latitude* - Longitude : *correct longitude*
X : undefined - Y : undefined
Printing outputpoint gives me this:
Array[1]
0:Object
spatialReference:Object
wkid:3297
type:"point"
x:"NaN"
y:"NaN"
__proto__:Object
length:1
__proto__:Array[0]
Getting why X and Y are undefined, but still not seeing why the projection didn't work.
**UPDATE**
I saw this info from another thread :
I had a similar problem, and found a soltuion that might help. I needed to project a mapPoint from 102100 to other systems using the GeometryService.Project, however this would consistently return a mapPoint with NaN coordinates. The solution was to first check that the map point is in 102100, if so pass this to the WebMercatorUtil.webMercatorToGeographic to get a latlong mappoint. Then use the geometry service to project this latlong mapPoint into whatever other coordsystem I needed. BTW, I'm working with the API for Flex.-Greg Nichols, TAIC
I was previously under the impression that my coordinates were GCS, but I may be wrong.
How to check what is the CS here? --> var lat = window.myMap.extent.getCenter().getLatitude().toFixed(2);
With that being said, I tried the following code :
var lat = window.myMap.extent.getCenter().getLatitude().toFixed(2);
var long = window.myMap.extent.getCenter().getLongitude().toFixed(2);
var latLong = "Latitude : " + lat + " - Longitude : " + long;
var X;
var Y;
var rgpfSixSudSR = new SpatialReference ({
wkid : 3297
});
var webMercatorSR = new SpatialReference ({
wkid : 102100
});
var geometryService = new GeometryService("http://ourserver/arcgis/rest/services/Utilities/Geometry/GeometryServer");
var mercatorPoint = new Point(lat, long, webMercatorSR);
var inputPoint = webMercatorUtils.webMercatorToGeographic(mercatorPoint);
console.log(inputPoint);
var prjParams = new ProjectParameters ();
prjParams.geometries = [inputPoint];
prjParams.outSR = rgpfSixSudSR;
geometryService.project(prjParams, function (outputpoint) {
console.log('Conversion completed');
X = outputpoint[0].x;
Y = outputpoint[0].y;
console.log(latLong);
console.log(center);
});
It prints out this :
Object
spatialReference: Object
type: "point"
x: -0.00015154578843096328
y: -0.0013529526492823366
__proto__: Object
Conversion completed
Latitude : -16.87 - Longitude : -150.61
X : undefined - Y : undefined
Note that I left the real "lat long" values, because I'm having doubts as to what is the correct wkid. Not sure now if it's 102100 or 4326...How can I check that?