사용자가지도를 클릭하면지도에서 좌표를 가져옵니다. 이제 이것을 저장하고 좌표를 다른 클래스에 전달하려고합니다. 답변을 아는 분이면 누구나 안내하십시오.자바에서 geoposition 위치를 저장하는 방법
감사
public class Corndinates extends MapClickListener{
/**
* Creates a mouse listener for the jxmapviewer which returns the
* GeoPosition of the the point where the mouse was clicked.
*
* @param viewer the jxmapviewer
*/
public Corndinates(JXMapViewer viewer) {
super(viewer);
}
@Override
public void mapClicked(GeoPosition location) {
GeoPosition cord = location;
System.out.println(cord);
}
}
내가 클래스 아래에 코드를 통과하고이 라인에 도착하는
가 // 첫 번째와 마지막 위치를 초기화 (프로그램 위치를 추가 할 여기에 마우스 클릭에서 좌표)
GeoPosition firstPoint = new GeoPosition(50.834722, 12.921389);
그러나 나는 코드에서 firstPoint 개체에 값을 넣는 방법을 모릅니다.
public class MapPanel {
public static void main(String args) {
System.out.println(args);
JFrame frame = new JFrame("FrameWork");
FrameWork frameWork = new FrameWork();
frame.setContentPane(frameWork.mainPanel);
// Create a TileFactoryInfo for OpenStreetMap
TileFactoryInfo info = new OSMTileFactoryInfo();
DefaultTileFactory tileFactory = new DefaultTileFactory(info);
frameWork.mapViewer.setTileFactory(tileFactory);
// Use 8 threads in parallel to load the tiles
//tileFactory.setThreadPoolSize(8);
//Initializing first and last position (program to get the coordinate from mouse click here)
GeoPosition firstPoint = new GeoPosition(50.834722, 12.921389);
GeoPosition lastPoint = new GeoPosition(50.839167, 12.9275);
// Create a track from the geo-positions
List<GeoPosition> track = Arrays.asList(firstPoint,lastPoint);
RoutePainter routePainter = new RoutePainter(track);
// Set the Default Location
GeoPosition chemnitz = new GeoPosition(50.833333, 12.916667);
//Set the focus
frameWork.mapViewer.setZoom(7);
frameWork.mapViewer.setAddressLocation(chemnitz);
// Add interactions
MouseInputListener mia = new PanMouseInputListener(frameWork.mapViewer);
frameWork.mapViewer.addMouseListener(mia);
frameWork.mapViewer.addMouseMotionListener(mia);
// frameWork.mapViewer.addMouseListener (새 CenterMapListener (frameWork.mapViewer)); frameWork.mapViewer.addMouseWheelListener (새로운 ZoomMouseWheelListenerCenter (frameWork.mapViewer)); // frameWork.mapViewer.addKeyListener (새 PanKeyListener (frameWork.mapViewer)); 난 당신이 파일에 정보를 저장하지 않으려 추정 다른 클래스에 전달함으로써
// Create waypoints from the geo-positions
Set<SwingWaypoint> waypoints = new HashSet<SwingWaypoint>(Arrays.asList(
new SwingWaypoint("Zentrum", firstPoint),
new SwingWaypoint("TU", lastPoint)));
// Create a waypoint painter that takes all the waypoints
WaypointPainter<Waypoint> waypointPainter = new WaypointPainter<Waypoint>();
waypointPainter.setWaypoints(waypoints);
// Create a compound painter that uses both the route-painter and the waypoint-painter
List<org.jxmapviewer.painter.Painter<JXMapViewer>> painters = new ArrayList<org.jxmapviewer.painter.Painter<JXMapViewer>>();
painters.add(routePainter);
painters.add(waypointPainter);
CompoundPainter<JXMapViewer> painter = new CompoundPainter<JXMapViewer>(painters);
frameWork.mapViewer.setOverlayPainter(painter);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
저장하는 것은 무엇을 의미합니까? DB에? – cralfaro
다른 클래스에서 좌표를 전달하는 방법에 대해 다른 클래스에서 사용하고 싶습니다. 또는 배열에 저장하는 방법? –
코드에 위도와 경도가 포함되어 있기 때문에 클래스에서이 좌표를 사용하려면 String 인수를 사용하십시오. –