0

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);
    }
scai
  • 20,297
  • 4
  • 56
  • 72
  • What part of the code do not work as expected? Post it here. – Artemix Jul 11 '13 at 13:22
  • code is too long i guess so i cant post but i am using simple threads to move my car around the map. and my car is moving randomly. but i want my car to move on particular streets just like google maps. and i dont know how to post my code here. it is too long! – siddharth kaneriya Jul 12 '13 at 12:48
  • sorry i am not able to rectify my code line by line! it is method i am using to locate my objects and car. car is moving but randomly. i doubt if this method is suitable for jxmapviewer. i think i have to use way points and i dont have any idea how to move such way points on the map using threads. – siddharth kaneriya Jul 12 '13 at 13:03
  • Please put your comments into your original question (you can always edit your questions). There you can format it for better readability. – Artemix Jul 12 '13 at 13:10
  • as you said i have put a part of my code in the original question! @Artemix – siddharth kaneriya Jul 15 '13 at 10:46

0 Answers0