我正在研究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);
}