I am working on Jxmapviewr/jxmapkit and my aim is to create an GPS kind of application using open street maps which shows the number of charging station and car object will be moving on the map through streets. Then i will try to find the nearest charging station using the current position of car. Some how i am able to print the stations on the open street maps but i could not manage to move my car(a simple rectangular object) on the streets! would you please help on this? thanks
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);
}