2014-10-09 5 views
3

Android 애플리케이션의 ArcGIS 맵에 마커를 추가하려고합니다. 그러나 그래픽 레이어를 추가하면 내지도가 나타나지 않습니다. Android 프로그래밍에 익숙하지 않아 도움이되었습니다. 내가 여기서 잘못하고있는 것이 확실하지 않습니다. 미리 감사드립니다.안드로이드의 ArcGIS 맵에 마커를 추가하려면 어떻게해야합니까?

public class SuggestionsFragment extends Fragment { 
    MapView mMapView; 
    GraphicsLayer graphicsLayer = new GraphicsLayer(); 
    Point point; 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
     Bundle savedInstanceState) { 
    View rootView = inflater.inflate(R.layout.fragment_suggestions, 
      container, false); 

    //Retrieve the map and initial extent from XML layout 
    mMapView = (MapView)rootView.findViewById(R.id.map); 

    //Create the layer 
    final Layer oneMapLayer = new ArcGISTiledMapServiceLayer("http://e1.onemap.sg/arcgis/rest/services/BASEMAP/MapServer"); 

    mMapView.addLayer(graphicsLayer); 
    Point point = new Point(1.3799775, 103.84877200000005); 
    graphicsLayer.addGraphic(new Graphic(point,new SimpleMarkerSymbol(Color.RED,10,STYLE.CIRCLE))); 

    //Know when the map layer loaded 
    mMapView.setOnStatusChangedListener(new OnStatusChangedListener() { 
     private static final long serialVersionUID = 1L; 

     public void onStatusChanged(Object source, STATUS status) { 
      if (source == oneMapLayer && status == STATUS.LAYER_LOADED) { 

       mMapView.centerAt(1.3799775, 103.84877200000005, false); 
       mMapView.setScale(1500,false); 


      } 
     } 
    }); 



    //Add dynamic layer to MapView 
    mMapView.addLayer(oneMapLayer); 




    return rootView; 
} 

@Override 
public void onDestroy() { 
    super.onDestroy(); 
} 

@Override 
public void onPause() { 
    super.onPause(); 
    mMapView.pause(); 
} 

@Override 
public void onResume() { 
    super.onResume(); 
    mMapView.unpause(); 
} 

} 
+0

지도가이 API 키 때문에입니다 나타나지 않으면 다음

내 코드입니다. – Abdellah

+0

답글 : @Abdellah하지만 제거하면지도가 나타납니다. mMapView.addLayer (graphicsLayer); 포인트 포인트 = 새 포인트 (1.3799775, 103.84877200000005); graphicsLayer.addGraphic (새 그래픽 (점, 새 SimpleMarkerSymbol (Color.RED, 10, STYLE.CIRCLE)))); – Alxy

답변

1

솔루션 :

public class SuggestionsFragment2 extends Fragment { 
MapView mMapView; 
GraphicsLayer graphicsLayer = new GraphicsLayer(); 
Point point; 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
     Bundle savedInstanceState) { 
    View rootView = inflater.inflate(R.layout.fragment_suggestions2, 
      container, false); 



    //Retrieve the map and initial extent from XML layout 
    mMapView = (MapView)rootView.findViewById(R.id.map); 

    //Create the layer 
    final Layer oneMapLayer = new ArcGISTiledMapServiceLayer("http://e1.onemap.sg/arcgis/rest/services/BASEMAP/MapServer"); 

    //Know when the map layer loaded 
    mMapView.setOnStatusChangedListener(new OnStatusChangedListener() { 
     private static final long serialVersionUID = 1L; 

     public void onStatusChanged(Object source, STATUS status) { 
      if (source == oneMapLayer && status == STATUS.LAYER_LOADED) { 

       mMapView.centerAt(1.3799775, 103.84877200000005, false); 
       mMapView.setScale(1500,false); 

       mMapView.addLayer(graphicsLayer); 
       Point point = GeometryEngine.project(x, y, mMapView.getSpatialReference()); 
       graphicsLayer.addGraphic(new Graphic(point,new SimpleMarkerSymbol(Color.RED,10,STYLE.CIRCLE))); 

      } 
     } 

    }); 

    //Add dynamic layer to MapView 
    mMapView.addLayer(oneMapLayer); 

    return rootView; 
} 

@Override 
public void onDestroy() { 
    super.onDestroy(); 
} 

@Override 
public void onPause() { 
    super.onPause(); 
    mMapView.pause(); 
} 

@Override 
public void onResume() { 
    super.onResume(); 
    mMapView.unpause(); 
} 
+0

여기에 ** x ** 및 ** y ** 값이 있습니까? – Nikhil

관련 문제