Select to view content in your preferred language

Lat Lon points in js api v2.0

1198
3
07-21-2010 10:35 AM
jorgelagos
New Contributor
I am upgrading an existing app that uses the JS api from v=1.4 to v=2.0. The new maps work good, when setting the extents it works great, but when I try to add a new marker, the marker appears in the west coast of Africa instead than on the specified Lat/Lon.

I am not that experienced with Geographical Information Systems so when I tried to search what I should do, I found threads related to the WKID that since this v2.0 uses 102100 I should use I different coordinate system instead of the degree based one, and that I should utilize webMercator utilities to translate the point. Unfortunately I have note been able to make sense of all this.

In a nutshell when using v1.4 I was able to create a point with like this:

    var point = new esri.geometry.Point(lon, lat);

In the API reference under the geometry -> point section, it illustrates that one way I can add a point is like this:

    new esri.geometry.Point(-118.15, 33.80, new esri.SpatialReference({ wkid: 4326 }))

So I just replaced the X and Y values with my lat and lon variables but when adding a graphics with that point, it is not placed anywhere near the desired place.

What am I doing wrong?
0 Kudos
3 Replies
derekswingley1
Deactivated User
Use esri.geometry.geographicToWebMercator() to convert your geometry from decimal degrees to meters so that it can be plotted on a basemap that uses the web mercator projection (wkid 102100, among others).

http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/namespace_geometry.htm#geographicToWeb...

The code would be something like this:
esri.geometry.geographicToWebMercator(
  new esri.geometry.Point(-118.15, 33.80, new esri.SpatialReference({ wkid: 4326 }))
);
0 Kudos
jorgelagos
New Contributor
That did it for me.

Thank you Very Much!
0 Kudos
XavierIrias
Occasional Contributor
When you use wkid 102100, and read points from the map, you will get values for x and y in a cartesian reference rather than geographic coordinates, and as noted the Javascript ESRI API provides convenience methods to convert to and from.  So far so good.

However, the calcs within the API seem to actually use the wrong WKID.  WKID 102100 is supposed to incorporate eccentricity, as opposed to the "old" WKID 102113, the spherical version.  According to the article "Migrating map tiling schemes" on the ESRI Resource Center, ArcGIS online services are now hosted in 102100 because it's "better". 

True enough, but when I test the actual conversions performed by the Javascript API, in fact they seem to still be using the spherical equations.  This does not make a huge difference but it's enough to notice, and enough to throw your calcs out of whack when you're trying to debug. 

I added the two spatial references to my converter utility so you can test this and other calcs out.  See http://ersquared.org:8080/marconitest/map/convert.jsp

On the left side, put in lat and long (remember longitude is negative in the US), choosing WGS84 as the datum.  On the right side, for destination coordinates, choose Web Mercator.  But then try the calc using WGS84 as the datum, and then the WGS84 spherical (as used in WDID 102113).  You will see that the spherical numbers are an exact match with the ESRI Javascript libraries, while the ellipsoidal version differs slightly.

I entered the various WKID parameters and did calcs, etc. in the hope that my problems had to do with wkid.  But they turned out to be far larger, so large that finetuning WKID is somewhat like arranging deck chairs on the Titanic, as long as fundamental browser problems exist.  As things stand now, I still can't place markers in the correct spot with Firefox.  I'm curious if you're using MSIE only, and that's why you can even notice other more subtle problems.
0 Kudos