Android ESRI地图获取无法生成图形错误的序列

时间:2013-11-28 13:25:38

标签: android esri

我正在使用以下代码在我的ESRI地图中添加图层。

public void footprintdata(String option)
 {  
  graphicsLayer.removeAll();

  if(option.equalsIgnoreCase("ALL"))
  {
   try 
   {    
    Graphic[] resultGraphics = new Graphic[footprintdata.size()];
    // Envelope to focus on the map extent on the results
    Envelope extent = new Envelope();

    for (i = 0; i < footprintdata.size(); i++) 
    {
     double lattitude = 0.0;
     double longitude = 0.0;  

     if(!footprintdata.get(i).getLatitude().equalsIgnoreCase(""))
     {
      lattitude = Double.parseDouble(footprintdata.get(i).getLatitude());
     }
     if(!footprintdata.get(i).getLongitude().equalsIgnoreCase(""))
     {
      longitude = Double.parseDouble(footprintdata.get(i).getLongitude());
     }     

     mLocation = new Point(XCoordinateFromLongitude(longitude), YCoordinateFromLatitude(lattitude));

     mapPoint = (Point) GeometryEngine.project(mLocation,
       SpatialReference.create(4326),mapView.getSpatialReference());  

     SimpleMarkerSymbol resultSymbol = new SimpleMarkerSymbol(Color.GREEN, 20, SimpleMarkerSymbol.STYLE.DIAMOND);
     // create graphic object for resulting location
     //PictureMarkerSymbol imagesymbolicon = new PictureMarkerSymbol(imagemarker(i));

     Graphic resultgraphics = new Graphic(mapPoint,resultSymbol);    
     resultGraphics[i] = resultgraphics;
     extent.merge(mapPoint);
    }

    graphicsLayer.addGraphics(resultGraphics);
    mapView.setExtent(extent, 100);
    mapView.zoomToResolution(mapPoint, 10);
    mapView.invalidate();


   } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
  }
  else
  {

   System.out.println("else of spinner selection");

   try 
   {    
    int count = 0;
    int temp = 1;
    for (int i = 0; i < footprintdata.size(); i++) {

     if (footprintdata.get(i).getLocationtype()
       .equalsIgnoreCase(spinner.getSelectedItem().toString())) {

      count++;
     }
    }

    System.out.println("count :"+ count);
    Graphic[] resultGraphics = new Graphic[count];
    Envelope extent = new Envelope(); 

    for (int i = 0; i < footprintdata.size(); i++) {

     //PictureMarkerSymbol imagesymbol = null;
     if (footprintdata.get(i).getLocationtype()
       .equalsIgnoreCase(spinner.getSelectedItem().toString())) {

      System.out.println("result success : "
        + footprintdata.get(i).getLocationtype());

      double lattitude = Double
      .parseDouble(footprintdata.get(i)
        .getLatitude());
      double longitude = Double
      .parseDouble(footprintdata.get(i) 
        .getLongitude());

      mLocation = new Point(XCoordinateFromLongitude(longitude), YCoordinateFromLatitude(lattitude));

      mapPoint = (Point) GeometryEngine.project(mLocation,
        SpatialReference.create(4326),mapView.getSpatialReference());

      SimpleMarkerSymbol resultSymbol = new SimpleMarkerSymbol(Color.GREEN, 20, SimpleMarkerSymbol.STYLE.DIAMOND);

      //PictureMarkerSymbol imagesymbolicon = new PictureMarkerSymbol(imagemarker(i));
      Graphic resultLocation = new Graphic(mapPoint,resultSymbol);

      System.out.println("temp :"+ temp);
      resultGraphics[temp] = resultLocation;
      extent.merge(mapPoint);
      temp++;

     }
    }

    graphicsLayer.addGraphics(resultGraphics);
    mapView.setExtent(extent, 100);
    mapView.zoomToResolution(mapPoint, 10);
    mapView.invalidate();    

   } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
  }
 }


public double YCoordinateFromLatitude(double latitude)
    {
        double rad = latitude * 0.0174532;
        double fsin = Math.sin(rad);
        double y = 6378137 / 2.0 * Math.log((1.0 + fsin) / (1.0 - fsin));

        return y;
    }   

    public double XCoordinateFromLongitude(double longitude)
    {
        double x = longitude * 0.017453292519943 * 6378137;
        return x;
    }

此代码首次正常运行。但之后我在My Logcat中获得了MapCore(24187): Failed to generate sequences for graphic。 如果有人对此有所了解,请提供帮助。

1 个答案:

答案 0 :(得分:0)

我通过删除这两种方法解决了这个问题: -

public double YCoordinateFromLatitude(double latitude)
    {
        double rad = latitude * 0.0174532;
        double fsin = Math.sin(rad);
        double y = 6378137 / 2.0 * Math.log((1.0 + fsin) / (1.0 - fsin));

        return y;
    }   

    public double XCoordinateFromLongitude(double longitude)
    {
        double x = longitude * 0.017453292519943 * 6378137;
        return x;
    }

这两种方法适用于IOS,但对于Android,我使用了以下行

mLocation = new Point(longitude,lattitude);

而不是

mLocation = new Point(XCoordinateFromLongitude(longitude), YCoordinateFromLatitude(lattitude));

这解决了我的问题。