×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 30
  1. #1
    Registered User
    Join Date
    May 2012
    Posts
    18

    [Ask] about Nokia Map API - Java ME

    hi, i'm arif..
    I'm making a map in the mobile application. I use Nokia Maps API. but, there are some questions about the Nokia Maps API.

    1. How to display Scale Bar and Compass directions in Nokia Map API?
    2. Can I use the A * algorithm for searching a route in Nokia Maps API?

    Thanks..

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,167

    Re: [Ask] about Nokia Map API - Java ME

    firstly please do observe the sections provided in this discussion baord, I moved this from the general discussions, and hoping that in future you would post these directly to corect places.

    Secondly, there is no point on repeating same questions over and over again, you have asked this alrerady in: http://www.developer.nokia.com/Commu...-Nokia-Map-API

    That thread did have pretty good answer for the routing, and for the scale & compass, there are no readymade APIs, so you would need to make those by yourself.

  3. #3
    Regular Contributor
    Join Date
    Aug 2011
    Location
    Berlin
    Posts
    288

    Re: [Ask] about Nokia Map API - Java ME

    To create a scalebar you will have to write you own MapComponent and add it to the map.
    Since the map is a Mercator projection, t he length of the bar will vary with the location displayed as the map stretches latitudes closer to the poles. Something like the code below will get you started.

    Code:
    ScaleBarComponent scaleBar = new ScaleBarComponent()
     map.addMapComponent(scaleBar);

    Code:
    public class ScaleBarComponent implements MapComponent {
    
        private MapDisplay map;
        private static final String ID = "ScaleBar";
        private static final String VERSION = "1.0";
        private int y_coord;
        private int x_coord_start;
        private int x_coord_end;
        private String text = "";
    
         final static int[] SCALE_IN_METRES = new int[]{5000000, 2000000, 1000000,
             600000, 300000, 150000, 75000, 30000, 20000, 10000, 5000, 2000, 1000,
             500, 250, 100, 50, 25};
    
         final static String[] SCALE_IN_METRES_TEXT = new String[]{"5000km", "2000km", "1000km",
             "600km", "300km", "150km", "75km", "30km", "20km", "10km", "5km", "2km", "1km",
             "500m", "250m", "100m", "50m", "25m"};
    
    
        /**
         * Attaches a Map to the Map Component.
         * @param map
         */
        public void attach(MapDisplay map) {
            this.map = map;
    
        }
    
        // from MapComponent
        public void detach(MapDisplay map) {
            this.map = null;
        }
    
        // from MapComponent
        public String getId() {
            return ID;
        }
    
        // from MapComponent
        public String getVersion() {
            return VERSION;
        }
    
        // from MapComponent
        public EventListener getEventListener() {
            return null;
        }
    
        /**
         * When the map is updated, we need to recalculate the length of the bar.
         * @param zoomChanged
         */
        public void mapUpdated(boolean zoomChanged) {
    
     x_coord_end = map.getWidth() - 20;
            y_coord = map.getHeight() - 20;
            double zoom = map.getZoomLevel();
            zoom = (zoom >= map.getMinZoomLevel()) ? zoom : map.getMinZoomLevel();
    
            if (zoom <= SCALE_IN_METRES.length - 1) {
                 GeoCoordinate end = map.pixelToGeo(new Point(x_coord_end, y_coord));
                 x_coord_start = x_coord_end - 10;
    
                 while (map.pixelToGeo(new Point(x_coord_start, y_coord)).distanceTo(end) < SCALE_IN_METRES[(int) zoom]) {
                     x_coord_start--;
                 }
    
                 text = SCALE_IN_METRES_TEXT[(int) zoom];
            }
        }
    
    
        public void paint(Graphics g) {
            //
    
            g.drawLine(x_coord_start, y_coord, x_coord_end, y_coord);
    
            g.drawLine(x_coord_start, y_coord + 2, x_coord_start, y_coord);
            g.drawLine(x_coord_end, y_coord + 2, x_coord_end, y_coord);
    
    
            g.drawString(
                     text, x_coord_end, y_coord, Graphics.BOTTOM | Graphics.
                    RIGHT);
        }
    }
    You could do something similar for a Compass, just add an image over the map instead.
    Last edited by jasfox; 2012-05-15 at 13:46.

  4. #4
    Registered User
    Join Date
    May 2012
    Posts
    18

    Re: [Ask] about Nokia Map API - Java ME

    @ mr.jasfox: thanks for you information, but i have question.
    private static final String VERSION = "1.0";
    what can only be used in version 1.0?

    @ mr.symbianyucca: i'm sorry for my mistake put this thread and repeating same questions
    I've read articles that you provide about routing.
    but I am still confused and I have some questions
    1. What algorithm is used for routing in Nokia Map API?
    2. Can I replace the algorithm with the algorithm I want?

    Thanks you

  5. #5
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,167

    Re: [Ask] about Nokia Map API - Java ME

    Quote Originally Posted by Arif_Mubashir View Post
    @ mr.jasfox: thanks for you information, but i have question.
    private static final String VERSION = "1.0";
    what can only be used in version 1.0?
    Please check the code, the explanation is included in there.. (i.e. its only version number for the component)

    Quote Originally Posted by Arif_Mubashir View Post
    @ mr.symbianyucca: i'm sorry for my mistake put this thread and repeating same questions
    I've read articles that you provide about routing.
    but I am still confused and I have some questions
    1. What algorithm is used for routing in Nokia Map API?
    2. Can I replace the algorithm with the algorithm I want?
    In general the routing is done in server, so you can not change algorithms for it, anyway, you could check what kind of setting options he API offers. Its your interface for the service, so you are bound to the options it is offering.

  6. #6
    Registered User
    Join Date
    May 2012
    Posts
    18

    Re: [Ask] about Nokia Map API - Java ME

    Quote Originally Posted by symbianyucca View Post
    Please check the code, the explanation is included in there.. (i.e. its only version number for the component)
    that mean, I can't use the Map API 0.5?



    Quote Originally Posted by symbianyucca View Post
    In general the routing is done in server, so you can not change algorithms for it, anyway, you could check what kind of setting options he API offers. Its your interface for the service, so you are bound to the options it is offering.
    What there is no way to change the routing algorithm?
    I still hope there is still a way to change it.

    thank you

  7. #7
    Regular Contributor
    Join Date
    Aug 2011
    Location
    Berlin
    Posts
    288

    Re: [Ask] about Nokia Map API - Java ME

    Quote Originally Posted by Arif_Mubashir View Post
    that mean, I can't use the Map API 0.5?
    You can use the component with any version of the API, as symbianyucca said, getVersion() just returns the version of the component, and does define not which version of the API is in use.

    In general you would be better off using the latest 1.0 version of the API as it incorporates new features, bug fixes and so on. If you look at this thread: http://www.developer.nokia.com/Commu...d-Java-SDK-1.1 as a workaround I would suggest you use 0.5 with the Asha 303 for now until a fix has been implemented, but hopefully the update will be available soon.

    Quote Originally Posted by Arif_Mubashir View Post
    What there is no way to change the routing algorithm?
    I still hope there is still a way to change it.
    You request a route as follows:

    Code:
    RoutingMode[] modes;
    WaypointParameterList wpl = new WaypointParameterList();
    RouteFactory.getInstance().createRouteRequest().calculateRoute(wpl, modes, this);
    To alter the routing algorthm you need to alter the mode look at the javadoc for full details of RoutingType, TransportMode and RoutingOptions constants.

    RoutingType covers things like fastest, shortest and economic
    TransportMode covers things like car, pedestrian and public transport
    RoutingOptions covers avoiding things like motorways or tunnels.

    Hopefully this should give you sufficient flexibility to get the route you want.
    You could of course manipulate the route you receive after making the request, or alternatively add more Waypoints to your journey to force the route to go via certain locations.

  8. #8
    Registered User
    Join Date
    May 2012
    Posts
    18

    Re: [Ask] about Nokia Map API - Java ME

    Quote Originally Posted by jasfox View Post
    You can use the component with any version of the API, as symbianyucca said, getVersion() just returns the version of the component, and does define not which version of the API is in use.

    In general you would be better off using the latest 1.0 version of the API as it incorporates new features, bug fixes and so on. If you look at this thread: http://www.developer.nokia.com/Commu...d-Java-SDK-1.1 as a workaround I would suggest you use 0.5 with the Asha 303 for now until a fix has been implemented, but hopefully the update will be available soon.
    Thanks for your information.

    Quote Originally Posted by jasfox View Post
    You request a route as follows:

    Code:
    RoutingMode[] modes;
    WaypointParameterList wpl = new WaypointParameterList();
    RouteFactory.getInstance().createRouteRequest().calculateRoute(wpl, modes, this);
    To alter the routing algorthm you need to alter the mode look at the javadoc for full details of RoutingType, TransportMode and RoutingOptions constants.

    RoutingType covers things like fastest, shortest and economic
    TransportMode covers things like car, pedestrian and public transport
    RoutingOptions covers avoiding things like motorways or tunnels.

    Hopefully this should give you sufficient flexibility to get the route you want.
    You could of course manipulate the route you receive after making the request, or alternatively add more Waypoints to your journey to force the route to go via certain locations.
    that means, I can use my own algorithm to do the routing? such Dijstra or A * Search etc.?

  9. #9
    Regular Contributor
    Join Date
    Aug 2011
    Location
    Berlin
    Posts
    288

    Re: [Ask] about Nokia Map API - Java ME

    Quote Originally Posted by Arif_Mubashir View Post
    that means, I can use my own algorithm to do the routing? such Dijstra or A * Search etc.?
    The API does not "do" the routing itself as the API does not have an on board routing algorthm. Instead it makes requests to a routing service. Calculating routes is a complex business, and the algorithms involved would be too much for a S40 device to handle. The API gives you the ability to add restrictions to your request so that that the routing service refines its response to meet your criteria.

  10. #10
    Registered User
    Join Date
    May 2012
    Posts
    18

    Re: [Ask] about Nokia Map API - Java ME

    Quote Originally Posted by jasfox View Post
    The API does not "do" the routing itself as the API does not have an on board routing algorthm. Instead it makes requests to a routing service. Calculating routes is a complex business, and the algorithms involved would be too much for a S40 device to handle. The API gives you the ability to add restrictions to your request so that that the routing service refines its response to meet your criteria.
    I want to know what algorithm to use Nokia Map 0.5 API for routing?
    Thanks

  11. #11
    Registered User
    Join Date
    May 2012
    Posts
    18

    Re: [Ask] about Nokia Map API - Java ME

    Quote Originally Posted by jasfox View Post
    Code:
    RoutingMode[] modes;
    WaypointParameterList wpl = new WaypointParameterList();
    RouteFactory.getInstance().createRouteRequest().calculateRoute(wpl, modes, this);
    I use the Nokia Map API 0.5
    But RouteFactory class was not found.
    What is the Nokia Map 0.5 API does not support RoutingFactory class?
    Thanks

  12. #12
    Registered User
    Join Date
    May 2012
    Posts
    18

    Re: [Ask] about Nokia Map API - Java ME

    I make the routing using the Nokia Map API 0.5
    but routing did not work.

    This code that I created
    Code:
    public class mnRute implements CommandListener {
    
        mnUtm midlet;
        Display display;
        skalaMap skala;
        legendaMap kompas;
        MapCanvas mapCanvas;
        MapDisplay mapDisplay;
        Command cmTujuan, cmRute, cmHapus, cmKembali;
        LocationProvider lp;
        MapStandardMarker awal,akhir;
        WaypointParameterList wpl;
        Route[] routes;
        MapFactory mapFactory;
    
        public mnRute(mnUtm midlet, Display display) {
            this.midlet = midlet;
            this.display = display;
            wpl = new WaypointParameterList();
            skala = new skalaMap();
            kompas = new legendaMap();
        }
    
        public void lokasiAwal() {
            try {
          //MAKE A MAP CANVAS
            mapCanvas = new MapCanvas(display);
            mapDisplay = mapCanvas.getMapDisplay();
            
            
          //Membuat Command
            cmKembali = new Command("Kembali", Command.BACK, 0);
            cmTujuan = new Command("Pilih Tujuan", Command.SCREEN, 1);
            cmHapus = new Command("Hapus Tujuan", Command.SCREEN, 2);
            cmRute = new Command("Cari Rute", Command.SCREEN, 3);
            mapCanvas.addCommand(cmKembali);
            mapCanvas.addCommand(cmTujuan);
            mapCanvas.addCommand(cmHapus);
            mapCanvas.addCommand(cmRute);
            mapCanvas.setCommandListener(this);
    
          //Menentukan Posisi Awal
            Criteria cr = new Criteria();
            cr.setHorizontalAccuracy(500);
    
            lp = LocationProvider.getInstance(cr);
    
            Location l = lp.getLocation(60);
            Coordinates c = l.getQualifiedCoordinates();
    
                if (c != null) {
                        double lat = c.getLatitude();
                        double lon = c.getLongitude();
    
                mapCanvas.getMapDisplay().setCenter(new GeoCoordinate(lat, lon, 0));
                mapCanvas.getMapDisplay().setZoomLevel(16,0,0);
    
          //MAKE CURRENT POSITION
                Point center = new Point(mapCanvas.getWidth()/2, mapCanvas.getHeight()/2);
                GeoCoordinate gc = mapDisplay.pixelToGeo(center);
                wpl.addCoordinate(gc);
                awal = mapCanvas.getMapFactory().createStandardMarker(gc, 10, null, MapShapeType.bed);
                mapDisplay.addMapObject(awal);
                mapDisplay.addMapComponent(skala);
                mapDisplay.addMapComponent(kompas);
           
         //Menampilkan Map
            display.setCurrent(mapCanvas);
    
                }
    
        } catch (Exception ex) {
            ex.printStackTrace();
            }
    
        }
    
        public void lokasiTujuan() {
          //MAKE A DESTINATION POINT
            Point center = new Point(mapCanvas.getWidth() / 2, mapCanvas.getHeight() / 2);
            GeoCoordinate gc = mapDisplay.pixelToGeo(center);
            wpl.addCoordinate(gc);
            akhir = mapCanvas.getMapFactory().createStandardMarker(gc, 10, null, MapShapeType.bed);
            mapDisplay.addMapObject(akhir);
            //mapCanvas.removeCommand(cmTujuan);
        }
    
        //CALCULATE ROUTE
        public void perhitungan(RoutingMode[] modes) {
          RouteManager rm = RouteManager.getInstance();
          rm.calculateRoute(wpl, modes);
          mapDisplay.removeAllMapObjects();
          routes = rm.getRoutes();
               for (int i = 0; i < routes.length; i++) {
                    mapDisplay.addMapObject(mapFactory.createMapPolyline(routes[i].getShape()));
                    mapDisplay.setCenter(routes[i].getStart().getMappedPosition());
          
        }
    
         }
    
      //EXECUTE ROUTING
      private void perutean(RoutingMode[] modes) {
            perhitungan(modes);
        }
    
        public void commandAction(Command c, Displayable d) {
          //Kembali ke Menu Utama
            if (c == cmKembali) {
               display.setCurrent(midlet.menu);
              }
              //Melakukan Penandaan Lokasi Tujuan
                if (c == cmTujuan) {
                    lokasiTujuan();
                }
                 if (c == cmRute) {
                    perutean(new RoutingMode[] { new RoutingMode() });
                 }
                  if (c == cmHapus) {
                      mapDisplay.removeAllMapObjects();
                  }
        
        }
    
    }
    I make a routing application with the current position as the starting position.

    errors in
    Code:
    //CALCULATE ROUTE
        public void perhitungan(RoutingMode[] modes) {
          RouteManager rm = RouteManager.getInstance();
          rm.calculateRoute(wpl, modes);
          mapDisplay.removeAllMapObjects();
          routes = rm.getRoutes();
               for (int i = 0; i < routes.length; i++) {
                    mapDisplay.addMapObject(mapFactory.createMapPolyline(routes[i].getShape()));
                    mapDisplay.setCenter(routes[i].getStart().getMappedPosition());
          
        }
    warning:
    java.lang.NullPointerException

    -----------------------------------------------------
    how to display the total distance between two points?

    I hope your help, please
    Thanks
    Last edited by Arif_Mubashir; 2012-05-22 at 05:17.

  13. #13
    Regular Contributor
    Join Date
    Aug 2011
    Location
    Berlin
    Posts
    288

    Re: [Ask] about Nokia Map API - Java ME

    1) Your NullPointerException is due to the fact that your mapFactory object has not been initialised.

    Either:
    Alter mnRute to Extend MapCanvas so that the protected mapFactory can be accessed from the base class.

    Or:
    create your own map factory using the static factory method : MapFactory.createMapFactory(int tileResolution, int width, int height)


    2) To obtain the length of a route use: Route.getSummary().getDistance(), to get an "as-the-crow-flies" distance you can Route.getStart().getMappedPosition().distanceTo(Route.getEnd().getMappedPosition())

    3) Nokia Map 0.5 is a beta release and there is no guarantee that the method signatures will be forward compatible. Hence the 'old' jar will not work with code written for the 1.x API. The method signatures of all associated location base service calls have been standardized from v 1.0 onwards.
    If you must use the old jar, there is a routing example bundled with the old 0.5 zip. I suggest you have a look at the routing demo code as a basis for your example to get it working.

  14. #14
    Regular Contributor
    Join Date
    Aug 2011
    Location
    Berlin
    Posts
    288

    Re: [Ask] about Nokia Map API - Java ME

    Quote Originally Posted by Arif_Mubashir View Post
    How to display Scale Bar and Compass directions in Nokia Map API?
    An article on how to do this has now been submitted to the Community Wiki: http://www.developer.nokia.com/Commu...leBarComponent

  15. #15
    Registered User
    Join Date
    May 2012
    Posts
    18

    Re: [Ask] about Nokia Map API - Java ME

    Quote Originally Posted by jasfox View Post
    Either:
    Alter mnRute to Extend MapCanvas so that the protected mapFactory can be accessed from the base class.
    what is the base class sir?

    i extend MapCanvas :

    Code:
    public class mnRute extends MapCanvas implements CommandListener {
    
        mnUtm midlet;
        //Display display;
        skalaMap skala;
        legendaMap kompas;
        MapCanvas mapCanvas;
        MapDisplay mapDisplay;
        Command cmTujuan, cmRute, cmHapus, cmKembali;
        LocationProvider lp;
        MapStandardMarker awal,akhir;
        WaypointParameterList wpl;
        Route[] routes;
        //MapFactory mapFactory;
    
        public mnRute(mnUtm midlet, Display display){
            super(display);
            wpl = new WaypointParameterList();
            skala = new skalaMap();
            kompas = new legendaMap();
            this.midlet = midlet;
            this.display = display;
        }
    
        public void lokasiAwal() {
            try {
          //Create map Canvas
          //Membuat Canvas Map
            mapCanvas = new MapCanvas(display);
            mapDisplay = mapCanvas.getMapDisplay();
            
          //Create Command
          //Membuat Command
            cmKembali = new Command("Kembali", Command.BACK, 0);
            cmTujuan = new Command("Pilih Tujuan", Command.SCREEN, 1);
            cmHapus = new Command("Hapus Tujuan", Command.SCREEN, 2);
            cmRute = new Command("Cari Rute", Command.SCREEN, 3);
            mapCanvas.addCommand(cmKembali);
            mapCanvas.addCommand(cmTujuan);
            //mapCanvas.addCommand(cmHapus);
            //mapCanvas.addCommand(cmRute);
            mapCanvas.setCommandListener(this);
    
          //Start position with current position
          //Menentukan Posisi Awal
            Criteria cr = new Criteria();
            cr.setHorizontalAccuracy(500);
    
            lp = LocationProvider.getInstance(cr);
    
            Location l = lp.getLocation(60);
            Coordinates c = l.getQualifiedCoordinates();
    
                if (c != null) {
                        double lat = c.getLatitude();
                        double lon = c.getLongitude();
    
                mapCanvas.getMapDisplay().setCenter(new GeoCoordinate(lat, lon, 0));
                mapCanvas.getMapDisplay().setZoomLevel(16,0,0);
    
          //Make end position marker
          //Membuat Tanda Posisi Awal di Map
                Point center = new Point(mapCanvas.getWidth()/2, mapCanvas.getHeight()/2);
                GeoCoordinate gc = mapDisplay.pixelToGeo(center);
                wpl.addCoordinate(gc);
                awal = mapCanvas.getMapFactory().createStandardMarker(gc, 10, null, MapShapeType.bed);
                mapDisplay.addMapObject(awal);
                mapDisplay.addMapComponent(skala);
                mapDisplay.addMapComponent(kompas);
    
         //displaying map
         //Menampilkan Map
            display.setCurrent(mapCanvas);
    
                }
    
        } catch (Exception ex) {
            ex.printStackTrace();
            }
    
        }
    
        //Make end position marker
        public void lokasiTujuan() {
          //Membuat Penanda Posisi Akhir
            Point center = new Point(mapCanvas.getWidth() / 2, mapCanvas.getHeight() / 2);
            GeoCoordinate gc = mapDisplay.pixelToGeo(center);
            wpl.addCoordinate(gc);
            akhir = mapCanvas.getMapFactory().createStandardMarker(gc, 10, null, MapShapeType.bed);
            mapDisplay.addMapObject(akhir);
            mapCanvas.removeCommand(cmTujuan);
        }
    
        //Calculate Route
        public void perhitungan(RoutingMode[] modes) {
          RouteManager rm = RouteManager.getInstance();
          rm.calculateRoute(wpl, modes);
          //mapDisplay.removeAllMapObjects();
          routes = rm.getRoutes();
               for (int i = 0; i < routes.length; i++) {
                   mapDisplay.addMapObject(mapFactory.createMapPolyline(routes[i].getShape()));
                   mapDisplay.setCenter(routes[i].getStart().getMappedPosition());
        }
    
         }
    
      private void perutean(RoutingMode[] modes) {
          perhitungan(modes);
        }
    
        public void commandAction(Command c, Displayable d) {
          //Kembali ke Menu Utama
            if (c == cmKembali) {
               display.setCurrent(midlet.menu);
              }
              //Melakukan Penandaan Lokasi Tujuan
              //Marking end position
                if (c == cmTujuan) {
                    lokasiTujuan();
                    mapCanvas.addCommand(cmTujuan);
                    mapCanvas.addCommand(cmHapus);
                    mapCanvas.addCommand(cmRute);
                }
                //Execute Route
                 if (c == cmRute) {
                    perutean(new RoutingMode[] { new RoutingMode() });
                 }
                  if (c == cmHapus) {
                      //lokasiAwal();
                      mapDisplay.removeAllMapObjects();
                      mapCanvas.addCommand(cmTujuan);
                  }
        
        }
    
    }
    polyline is not display and no warning error
    why the polyline is not display?

    Thanks sir..
    Last edited by Arif_Mubashir; 2012-05-30 at 15:35.

Similar Threads

  1. Nokia java sdk 1.0 does not find java
    By jkekoni in forum Mobile Java Tools & SDKs
    Replies: 1
    Last Post: 2011-08-11, 13:30
  2. Replies: 5
    Last Post: 2011-02-02, 14:40
  3. What version of Java Card is the internal Java Card of Nokia 6212?
    By mmattsso in forum Mobile Java Tools & SDKs
    Replies: 0
    Last Post: 2010-03-30, 10:32
  4. Java Nokia 9300 opening JAVA 2.4.3 applet ?
    By bartd914 in forum Mobile Java General
    Replies: 2
    Last Post: 2006-03-31, 18:16
  5. Replies: 0
    Last Post: 2004-09-15, 11:46

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×