karinxx92

problem with getGraphicIDs()

Discussion created by karinxx92 on Jun 12, 2013
Hi,

I am having some problem when it comes to using the method getGraphicIDs for graphic layers.

I have a single tap function that is called when the map is pressed. It will create one circular point graphic on the map for the first 3 taps, and subsequently, the method getGraphicIDs is used to determine whether I have clicked on one of the graphics created.

However, this method works well if i click on the graphics created, but once i click somewhere else on the map where there is no graphics, my program closes and exits unexpectedly. Is there any issue with this? Please help!!

Below is my code snippets:

public boolean onSingleTap(MotionEvent e){

float x = e.getX();
float y = e.getY();
Point screenPoint = new Point(x,y);
Point mapPoint = map.toMapPoint(screenPoint);

if (graphicsLayer.getNumberOfGraphics() <=3){
 
  Graphic graphic = new Graphic(mapPoint,new SimpleMarkerSimbol(Color.BLUE,25,Style.CIRCLE));
  graphicsLayer.addGraphic(graphic);
 }
 else{
  int[] ids = graphicsLayer.getGraphicIDs(x,y,7);
  if(ids != null){
  Toast toast1 = Toast.makeText(project.this,"Graphic selected", Toast.LENGTH_SHORT);
  toast1.show;
  }
  else{
  Toast toast2 = Toast.makeText(project.this,"No graphic selected", Toast.LENGTH_SHORT);
  toast2.show;
  }
 }
return true;
}

Attachments

Outcomes