jxmapviewer如何在java中保存地理位置
当用户点击地图时,我从地图上获取坐标。现在我想保存这个,并将坐标传递给另一个类。如果有人知道答案,请引导
谢谢
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);
但我不知道如何把价值从电线第一点的对象
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);
//框架。地图查看器。addMouseListener(新的CenterMapListener(frameWork.mapViewer)); 框架地图查看器。addMouseWheelListener(新ZoomMouseWheelListenerCenter(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);
}
}
# 1 楼答案
顺便说一句,我想你是想避免将信息保存到文件中。下面的代码将把代码传递到新类中