Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Feb 2010

    read landmark text

    dear sir
    i want to a code to read a text file containing the coordinate of landmark and draw points on an image at all this coordinates
    with best regard

  2. #2
    Super Contributor
    Join Date
    May 2008
    Helsinki, Finland

    Re: read landmark text

    Hello souhir, and welcome to the discussion board!

    This should help you to read a text file (replace 'myfile' is whatever your file is named):

    private String file(){
        InputStream is = getClass().getResourceAsStream("myfile.txt");
        StringBuffer sb = new StringBuffer();
          int chars, 
          i = 0;
          while ((chars = is.read()) != -1){
            sb.append((char) chars);
          return sb.toString();
        }catch (Exception e){}
        return null;
    Then, if you already have the latitudes and longitudes for your 'landmarks' in that file, then yes - you could set 'points' or 'markers' at those geocoordinate locations. Now where I would need more information, to be able to help you better, is to know what would that 'image' be, that you mentioned? Do you mean you would be using e.g. some maps API, perhaps?

    Because mapping the latitude and longitude would be relative to that context - it would be different to having an image and just setting points on it, based on x,y coordinates.

    But let's say you would have an image only. On a MIDlet you would read the image first and display it, in the following manner e.g.:

    import java.io.*;
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    class myCanvas extends Canvas {
      Image myImage;
      public myCanvas () {
        try {
          myImage = Image.createImage ("/myimage.png");  // replace 'myimage.png' with your file
        catch (IOException e) {
          throw new RuntimeException ("Failed loading image: "+e);
    // or plain on-the-fly by modifying with this:
    public myCanvas () {
      myImage = Image.createImage (10,10);
    /* or plain on Form instead of using canvas
    private Form f;
    Form f = new Form("My Form");
            Image myImage = Image.createImage("myimage.png");  // depending where your image is e.g. "/res/myimage.png")
            }catch(java.io.IOException e){e.printStackTrace();}

    When you have image loaded on canvas, you can draw your line(s) over it, if the line is short enough, it makes a dot.

    : g.drawLine (0, 0, 100, 200); (where g = Graphics):


    But if you have time to examine these and also provide a little more details were you up to doing maps API based drawing...?

    ...set and create Canvas...
    try {
    	// load an image from file system
    	Image myImage = Image.createImage("/myimage.png"); // gif, jpg...
     	// get graphics object and set drawing color to red
    	Graphics myGraph = myImage.getGraphics();
            // draw loaded image        
    	myGraph.drawImage(myImage, 0, 0, 0);
    	// draw a line on it
    	myGraph.drawLine(0, 0, 25, 19);
            /* when drawing an image should also notify screen sizing and positioning
               shows one way to position.
    		offImg, getWidth()/2,
    		getHeight()/2 + 10,
    		Graphics.HCENTER | Graphics.TOP);
    } catch(Exception e) { e.printStackTrace(); }

    Best Regards,
    [FONT="Comic Sans MS"][COLOR="Blue"][/COLOR][I]Marko Lumivuori
    Technical Support
    +358 40 8019330

Similar Threads

  1. Read from a text file
    By razas in forum Symbian
    Replies: 4
    Last Post: 2010-12-06, 05:53
  2. Replies: 8
    Last Post: 2009-12-09, 06:27
  3. how can read text in the text box
    By Gill in forum Symbian
    Replies: 4
    Last Post: 2008-11-14, 05:50
  4. Read text Line from text File
    By CarusoAlex in forum Symbian
    Replies: 4
    Last Post: 2008-02-06, 12:24
  5. Read text file line by line
    By fdelvalle in forum Symbian
    Replies: 5
    Last Post: 2007-01-31, 09:48

Posting Permissions

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