Select to view content in your preferred language

lat/lng MapPoint

2000
3
06-20-2012 01:04 AM
AmirBabiker
New Contributor
Hi guys,

how to create a MapPoint using lat/lng values ? i want to add a marker according to lat and lng values ..

thanx in advance
Tags (2)
0 Kudos
3 Replies
JoeHershman
MVP Regular Contributor
Depends on the SpatialReference of your map.  If your map is in WGS84 then it is simply:

X = Longitude
Y = Latitude

Otherwise use the WebMercatorMapPoint class.
Thanks,
-Joe
0 Kudos
AmirBabiker
New Contributor
Thanks for the reply .. well i'll still a newbie in arcgis api so i might need a little more help .. my map wkid is 4326 102100

my code so far
                     // lat,lng values
                          var mp:MapPoint = new MapPoint(lat,lng);
      var mp2:MapPoint = (WebMercatorUtil.geographicToWebMercator(mp) as MapPoint);
      mp2.spatialReference = new SpatialReference(102100);
0 Kudos
JoeHershman
MVP Regular Contributor
Thanks for the reply .. well i'll still a newbie in arcgis api so i might need a little more help .. my map wkid is 4326 102100



You map is either 4326 or 102100 those are two different SpatialReferences.  4326 is WGS84 which uses Lat and Long.  So if your coordinates are Latitude and Longitude then the SpatialRefernce for those points is 4326.  Your map may be in 102100 (Web Mercator), if you are using ArcGIS On-Line or Bing for a basemap this is the SpatialReference of the Map.

When you set the SpatialReference or the point it needs to be the based on the coordinates of the point not of the Map.  Also you have the coordinates flipped, X=Longitude, Y=Latitude like I mentioned in the previous post, which is probably the issue because it seems like you are projecting.  You may want to explicitly set the SpatialReference of the point before you convert

                // lat,lng values
               var mp:MapPoint = new MapPoint(lat,lng);
               mp.SpatialReference = new SpatialReference(4326) //Set explicitly
         
               var mp2:MapPoint = (WebMercatorUtil.geographicToWebMercator(mp) as MapPoint);
//I don't think this next line is necessary, if you look in the debugger I think you will see SpatialReference is already set - but not 100% sure
               mp2.spatialReference = new SpatialReference(102100);


Hope that helps
Thanks,
-Joe
0 Kudos