2013-11-28 45 views
0

我正在使用以下代碼在我的ESRI地圖中添加圖形圖層。Android 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; 
    } 

此代碼在第一時間正常工作。但在此之後,我在我的Logcat中獲得MapCore(24187): Failed to generate sequences for graphic。 如果有人對此有任何想法,請幫助。

回答

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)); 

這解決了我的問題。