java保存位置,如何在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 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(new CenterMapListener(frameWork.mapViewer));

frameWork.mapViewer.addMouseWheelListener(new ZoomMouseWheelListenerCenter(frameWork.mapViewer));

// frameWork.mapViewer.addKeyListener(new PanKeyListener(frameWork.mapViewer));

// Create waypoints from the geo-positions

Set waypoints = new HashSet(Arrays.asList(

new SwingWaypoint("Zentrum", firstPoint),

new SwingWaypoint("TU", lastPoint)));

// Create a waypoint painter that takes all the waypoints

WaypointPainter waypointPainter = new WaypointPainter();

waypointPainter.setWaypoints(waypoints);

// Create a compound painter that uses both the route-painter and the waypoint-painter

List> painters = new ArrayList>();

painters.add(routePainter);

painters.add(waypointPainter);

CompoundPainter painter = new CompoundPainter(painters);

frameWork.mapViewer.setOverlayPainter(painter);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.pack();

frame.setVisible(true);

}}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值