set graphic on a location(lat-lon)

2286
1
01-19-2014 11:59 PM
razmaimon
New Contributor
Good day all,

I am a bit NOOB here....so sorry for the basic question here...

I took the HelloWorld sample and now i want to add a Red circle on a location using lat-lon, for example:
double locx = 32.062910;
double locy = 34.780891;
SimpleMarkerSymbol symbol new SimpleMarkerSymbol(Color.RED,25, SimpleMarkerSymbol.STYLE.CIRCLE)

i've added a GraphicsLayer to my MapView
and now i'm stuck...
If i try to add a new Graphic to my GraphicsLayer using my lat-lon the marker apears in the middle of the map.
I use :
new Graphic(new Point(locx, locy), symbol));


can someone explain how to set the graphic in the correct place?

also, in the sample main.xml layout file,
you set the attribute initExtent. what does it mean?!?!
(initExtent = "-19332033.11, -3516.27, -1720941.80, 11737211.28")

Thanks,
Raz
0 Kudos
1 Reply
ShellyGill1
Esri Contributor
Hi Raz - all questions are welcome, experts or beginners!

The simple answer is you need to change your latitude,longitude coordinates to the same system that is used in the map, then your point should show up where you expect it to be. Try changing the line that adds the graphic to this, where the points are projected, and then used in the graphic:

Point pt = GeometryEngine.project(locx,  locy,  mMapView.getSpatialReference());
Graphic g = new Graphic(pt, symbol); 


Some more background on this - when you create a map, the spatial reference is automatically set, and matches the spatial reference of the first layer that you added. A spatial reference defines what system of coordinates are used for that map - there are thousands of systems, but typically most people only have to think about one or two.

In the Hello World sample, the MapView has the 'Topo' basemap set in the layout, main.xml. All of Esri's basemaps use a system called  Web Mercator Auxilliary Sphere which does not use latitude,longitude, it uses a grid of meters. So your lat,long coordinates dont match with the basemap in the place you'd expect. You can use the Project method on the GeometryEngine class to change between the common systems:
https://developers.arcgis.com/en/android/api-reference/reference/com/esri/core/geometry/GeometryEngi...

In the code above, the project method is assuming you have latitude,longitude coordinates using the WGS 84 coordinate system, which is one of the most common. It depends where you got the coordinates from as to what system they might use, but there's a fairly good chance this is suitable. The second parameters indicates that you want to project to the system used by the MapView.


you set the attribute initExtent. what does it mean?!?!
(initExtent = "-19332033.11, -3516.27, -1720941.80, 11737211.28")

So this is just some coordinates of xmin,ymin etc but using the web mercator auxiliary sphere system, not latitude and longitude.
0 Kudos