Select to view content in your preferred language

Is there a WebMercatorUtil class?

554
3
05-10-2010 05:05 AM
MapEnglish
Frequent Contributor
Hi:

Will there be a WebMercatorUtil class available in the iPhone API, similar to the Flex API? This is a popular and convenient class in the Flex API for taking lat/lon geocoding results and projecting them to Web Mercator for display on modern basemaps. Or do we need to use the AGSGeometryService task?

Trying to keep the lines of code to a minimum,
Matt English
0 Kudos
3 Replies
MikeQuetel
Deactivated User
Hi:

Will there be a WebMercatorUtil class available in the iPhone API, similar to the Flex API? This is a popular and convenient class in the Flex API for taking lat/lon geocoding results and projecting them to Web Mercator for display on modern basemaps. Or do we need to use the AGSGeometryService task?

Trying to keep the lines of code to a minimum,
Matt English


If this is something you need now, here are a couple javascript functions that you could port to Obj C.  I wouldn't go back to the server for that kind of thing if at all possible.

      function ll2meters(lat,lon) {
        // Converts given lat/lon in WGS84 Datum to XY in Spherical Mercator EPSG:900913
        var originShift = 2 * Pi() * 6378137 / 2.0;                     
        var ret = StructNew(); mx=0; my=0;
        mx = lon * originShift / 180.0;
        my = Log(Tan((90 + lat) * Pi() / 360.0 )) / (Pi() / 180.0);
        my = my * originShift / 180.0;
        ret.x = mx;
        ret.y = my; 
        return ret;
      }

      function meters2ll(mx,my) {
        // Converts XY point from Spherical Mercator EPSG:900913 to lat/lon in WGS84 Datum"
        var originShift = 2 * Pi() * 6378137 / 2.0;                     
        var ret=StructNew(); lon=0; lat=0;
        lon = (mx / originShift) * 180.0;
        lat = (my / originShift) * 180.0;
        lat = 180 / Pi() * (2 * Atan( Exp( lat * Pi() / 180.0)) - Pi() / 2.0);
        ret.lat = lat;
        ret.lon = lon;    
        return ret;
      }  
0 Kudos
DiveshGoyal
Esri Regular Contributor
A couple of global functions which you can use

AGSGeometryGeographicToWebMercator
AGSGeometryWebMercatorToGeographic



For some reason, the API ref is currently not picking up these global functions. We'll try to get that resolved.
_
Divesh
0 Kudos
JustinCarasick
Emerging Contributor
very nice. thanks for sharing that tidbit.
0 Kudos