×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    3

    Nokia maps with Lwuit

    Hi,
    I am brazilian, and sorry my bad english.
    I like to use maps api with Lwuit.
    But i don't know how.
    Because I like to put the map inside a Form and use components of Lwuit like command and others.
    For maintain the visual of my application
    Without the lwuit I can work.

  2. #2
    Regular Contributor
    Join Date
    Aug 2011
    Location
    Berlin
    Posts
    289

    Re: Nokia maps with Lwuit

    There are several ways you could do this, ranging from the very simple to the more complex. The approach you should take would depend upon what you are planning to do with them map.

    1) The simplest method would be to use the RESTful Maps API directly within a lwuit HTMLComponent - If you include the hc parameter, the map returned will be formatted HTML which the component can already render:

    Code:
    HttpRequestHandler handler = new HttpRequestHandler();
    HTMLComponent htmlC = new HTMLComponent(handler);
    htmlC.setPage("http://m.nok.it/?c=-23.561389,-46.656389&h=400&w=330&hc&nord&z=15");
    The API reference can be found here : http://www.developer.nokia.com/Devel...API_Reference/

    At a minimum, you would need to supply the longitude, latitude and zoom level.

    The advantage of this method is it is very easy to implement and professionally styled.
    The disadvantage is that it is inflexible. If the map returned by the hc parameter isn't what you want then you need another approach.

    2) The next level up in complexity would be to create your own class extending the lwuit Component , and use the RESTful Maps API (again) in the override of the paint() method

    Code:
    public class MyComponent extends Component {
    public void paint(Graphics g) {
    im = getImage()
    if (im != null) {
                g.drawImage(im, 10, 10, Graphics.LEFT | Graphics.TOP);
            }
    }
    }
    An example of how to create the URL and retrieve the Image in getImage() method can be seen here: http://www.developer.nokia.com/Commu...I_with_Java_ME

    You could of course extend the paint() method add to additional stuff over the map, such as text for example.

    For both of the methods discussed so far, every alteration will invoke a new http request and will require another image to be downloaded.

    3) It is possible (though slightly complex) to combine Canvas based operations with lwuit, through creating a lwuit component as a wrapper and then moving the canvas paint() code inside the component paint() method.

    The code would be very similar to the CustomMapItem described here:

    http://www.developer.nokia.com/Commu...PI_for_Java_ME

    (though it would extend the lwuit Component rather CustomItem) - access to the mapFactory would then allow you to add markers and so on.

    You would the be able to take advantage of the in-built map tiling and caching , which would reduce the network traffic. The only disadvantage of this method is that you wouldn't get panning, zoom or interactivity out of the box. You would need to add methods to do this to your Component Event Handling interface if you need them.

    Option 3) would be the most comprehensive solution, though I would definitely recommend you comprehensively test your solution on various devices. Since Options 1) and 2) are http based, they should work easily on any device, and may be acceptable to you if you do not need to keep regularly updating your map.

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    12

    Re: Nokia maps with Lwuit

    LWUIT development has now migrated to Codename One which has a map component. You should check it out.

  4. #4
    Registered User
    Join Date
    Apr 2012
    Posts
    3

    Re: Nokia maps with Lwuit

    This api works only in nokia phone?

  5. #5
    Regular Contributor
    Join Date
    Aug 2011
    Location
    Berlin
    Posts
    289

    Re: Nokia maps with Lwuit

    The API is a java jar, so provided you are targeting phones with CLDC 1.1 and MIDP-2.0 or higher it should work.
    As was mentioned in this thread http://www.developer.nokia.com/Commu...to-the-project , you may need to include a reference to the Web-services optional package jsr172 for KML support.

    Java is supposed to be "Write once, run anywhere", but there will be potentially subtle differences in the JVM implementations so the usual caveat will be to test on multiple target phones.
    see this link for more details: http://en.wikipedia.org/wiki/Write_once,_run_anywhere

  6. #6
    Registered User
    Join Date
    Apr 2012
    Posts
    3

    Re: Nokia maps with Lwuit

    When I try use the Java Micro Edition SDK 3.0 appears the message.
    Copyrights not available. An error occurred while trying to download the copyrights. Please check your internet settings. Application not authorized to access the restricted API
    if I use the nokia sdk 1.1 works fine.
    My question is, in non nokia phones go happen the same thing?

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

    Re: Nokia maps with Lwuit

    I'm guessing that the Java Micro Edition SDK 3.0 emulator you are using has an overly strict interpretation of the DNS specification, and therefore is failing to accept the hostname of the international map server when attempting to get the map copyright. This is not an issue with the map server in Beijing.

    A similar compatibility problem was found with the old Sun 2.5.2 WTK development kit, and a workaround can be added as follows:

    Code:
            
    // Due to an issue with the hostnames that are used it is not possible to use
    // international maps at this stage on the WTK emulators. 
            if ("SunMicrosystems_wtk".equals(
                    System.getProperty("microedition.platform"))) {
                ApplicationContext.getInstance().setChina(true);
            }
    The devices and Nokia emulators do not suffer from this limitation. My assumption is that the return value of the System.getProperty("microedition.platform") may have changed, and is no longer SunMicrosystems_wtk for the newer Java Micro Edition SDK 3.0, so you may need to send the
    System.getProperty("microedition.platform") to output to check what the value is first.

    The SDK you use should be irrelevant, as it is merely emulating a device. Personally I tend to use the Nokia SDK 1.0, as the examples were created using it.


    You could of course hard code your app to use the Beijing server in all instances:
    Code:
    ApplicationContext.getInstance().setChina(true);
    Java programming doesn't always live up to the ideal of being automatically portable. You have come across an example of the subverted Java maxim "Write once, debug everywhere"

Similar Threads

  1. Is there a way to convert Maps Data from Nokia Maps 3 to be compatible with N Maps 2
    By dimchopicha in forum General Development Questions
    Replies: 6
    Last Post: 2011-01-09, 17:50
  2. Navigation route coordinates from Nokia Maps or Ovi Maps
    By selimsolmaz in forum Mobile Java Tools & SDKs
    Replies: 2
    Last Post: 2010-03-04, 10:02
  3. Replies: 3
    Last Post: 2010-03-03, 10:25

Posting Permissions

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