Select to view content in your preferred language

Adding a graphic on a spefisific location on the map

1910
3
01-17-2012 11:36 PM
_lkerArg_n
Emerging Contributor
Below is the part of the application code that I've written. When the application is run, the graphic is added on the map. Hovewer, it is not in the right location though the lattitude and longitude values are right. What could be the reason? I could not figure it out.
                
                someGraphicsLayer = new GraphicsLayer();
  map.addLayer(someGraphicsLayer);

  HashMap<String, Object> attrMap = new HashMap<String, Object>();
  attrMap.put("Title", "a graphic");

  double locx = 32.039821;
  double locy = 39.8858262;
  
                Point p = new Point(locx, locy);
  Point point = (Point) GeometryEngine.project(p, SpatialReference.create(4326), map.getSpatialReference());    

  Symbol symbol = someIcon;

  someGraphicsLayer.addGraphic(new Graphic(point, symbol, attrMap, null));
0 Kudos
3 Replies
IvanBespalov
Frequent Contributor
mggl (sorry your name is not readable "?lker"),

seems like you need to refresh graphics layer, after graphics is added:

graphicsLayer.postInvalidate();


How Android Draws

postInvalidate()
0 Kudos
_lkerArg_n
Emerging Contributor
mggl (sorry your name is not readable "?lker"),

seems like you need to refresh graphics layer, after graphics is added:

graphicsLayer.postInvalidate();


How Android Draws

postInvalidate()


Graphic is already seen on the map, but in the wrong place. The graphic is always seen at position ( lattitude = 0, longitude = 0) It turned out that the problem was map is not loaded. Thus, I added and asynchronus task which loops until the map is loaded and then adds the graphic later.

Anyway, thanks for the answer, I should add that line of code, too.
0 Kudos
SebastianGreifeneder1
Occasional Contributor
Instead of using an asynchronous task you can do something like this:

mapView.setOnStatusChangedListener(new OnStatusChangedListener() {
public void onStatusChanged(Object source, STATUS status) {

          if (status == STATUS.INITIALIZED) {
            ...
          }
        }
      });
0 Kudos