JXmapviewer工具包

时间:2013-07-11 12:57:05

标签: java desktop-application jxmapkit jxmapviewer

我正在研究 Jxmapviewr / jxmapkit ,我的目标是使用开放的街道地图创建一种GPS应用程序,显示充电站和汽车对象的数量将通过街道在地图上移动。然后我将尝试使用当前的汽车位置找到最近的充电站。有些我怎么能在开放的街道地图上打印车站,但我无法在街道上移动我的车(一个简单的矩形物体)!你能帮忙吗?感谢

public void addWaypoint(final JSONObject geoInfo) 
 {
Set<Waypoint> waypoints = new HashSet<Waypoint>();

Double  latitude=Double.parseDouble(geoInfo.get("latitude")+"");
Double  longitude=Double.parseDouble(geoInfo.get("longitude")+"");

waypoints.add(new Waypoint(latitude,longitude));

WaypointPainter painter = new WaypointPainter();
painter.setWaypoints(waypoints);
painter.setRenderer(new WaypointRenderer() {

     @Override
      public boolean paintWaypoint(Graphics2D g, JXMapViewer map, Waypoint wp) {

     g.draw3DRect(startAtX,startAtY, 10, 10, true);
    int incrementX = (int)(Math.random()*4);
    if((Math.random()*6)>4){
        incrementX = incrementX*-1;
    }
    int incrementY = (int)(Math.random()*2);

    startAtX=startAtX+incrementX;
    startAtY=startAtY+incrementY;
        JSONObject obj=null;
        try {
            obj = (JSONObject) new JSONParser().parse(new FileReader(
                "test1.json"));
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        stations = (JSONArray) obj.get("station");
    for(int i=0;i<stations.size();i++){
        String statX = (String)((JSONObject)stations.get(i)).get("x");
        String statY = (String)((JSONObject)stations.get(i)).get("y");

     (int)Float.parseFloat(statY), null);
    g.fillRect((int)Float.parseFloat(statX),(int)Float.parseFloat(statY), 10, 10);
    g.drawString((String)((JSONObject)stations.get(i)).get("stationName"),
     (int)Float.parseFloat(statX), (int)Float.parseFloat(statY));

    }
   if(startAtY > getHeight()){
       startAtY = 50;
   }
   if(startAtX > getHeight()){
       startAtX = 50;
   }
    doDrawing(g);
     g.fillRect(1, 1, 30, 30);
    return true;
   }

   });

    jXMapKit.getMainMap().setOverlayPainter(painter);
    }

0 个答案:

没有答案