Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7661549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:36:47+00:00 2026-05-31T13:36:47+00:00

Hi I am creating an application that will draw lines over the top of

  • 0

Hi I am creating an application that will draw lines over the top of a MapView using Overlays. For the moment I have set GPS points that I want to use the projection.toPixel() method on. The method does not throw up any errors but the points do not stay fixed on the map when the map is moved as they should. Is there something I am missing?

//Zoom into certain area
public boolean onKeyDown(int keyCode, KeyEvent event)
{ 
    MapController mc = mapView.getController();

    switch(keyCode)
    {
        case KeyEvent.KEYCODE_1:
            mc.zoomIn();
            break;

        case KeyEvent.KEYCODE_2:
            mc.zoomOut();
            break;

        case KeyEvent.KEYCODE_4:
            //Create new path
            path = new Path();

            //Get Location Data from GPS

            p = new GeoPoint(
                    (int) (54.9886454 * 1E6),
                    (int) (-7.522208 * 1E6));

            //Convert GPS location to Screen Pixels
            Point screenPts1 = new Point();

            mapView.getProjection().toPixels(p,  screenPts1);

            //Start Path and pass locations
            path.moveTo(screenPts1.x, screenPts1.y);
            path.lineTo(screenPts1.x, screenPts1.y);

            System.out.println("New Path ");
            break;  

        case KeyEvent.KEYCODE_5:                
            //Get Location Data from GPS

            p = new GeoPoint(
                    (int) (54.9984931 * 1E6),
                    (int) (-7.522208 * 1E6));

            //Convert GPS location to Screen Pixels
            Point screenPts2 = new Point();
            mapView.getProjection().toPixels(p,  screenPts2);

            //Pass locations to the path
            path.lineTo(screenPts2.x, screenPts2.y);

            System.out.println("Continue Path ");
            break;  

        case KeyEvent.KEYCODE_6:                
            //Get Location Data from GPS

            p = new GeoPoint(
                    (int) (54.9994777 * 1E6),
                    (int) (-7.5005787 * 1E6));

            //Convert GPS location to Screen Pixels
            Point screenPts3 = new Point();
            mapView.getProjection().toPixels(p, screenPts3);

            //Pass locations to the path
            path.lineTo(screenPts3.x, screenPts3.y);

            //Close the path and add it to the _graphics array for it to be drawn
            _graphics.add(path);

            System.out.println("End Path ");

            break;  
    }
    return super.onKeyDown(keyCode, event);
}

Overlay Class draw Method:

public boolean draw(Canvas canvas, MapView mapView, boolean shadow,long when)
    {       
        super.draw(canvas,mapView,shadow);

        //-- Create new paint object --
        Paint mPaint = new Paint();
        mPaint.setDither(true);
        mPaint.setColor(Color.RED);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeJoin(Paint.Join.ROUND);
        mPaint.setStrokeCap(Paint.Cap.ROUND);
        mPaint.setStrokeWidth(2);

        //-- Take all the paths from the _graphics array and draw them to the Screen --
        for (Path path : _graphics) 
        {
            canvas.drawPath(path, mPaint);  
        }

        return true;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:36:47+00:00Added an answer on May 31, 2026 at 1:36 pm

    From documentation of MapView.getProjection() method: “The Projection of the map in its current state. You should not hold on to this object for more than one draw, since the projection of the map could change.”

    So when you move the map, you have to recalculate the pixel locations, because the projection with which you calculated the previous pixel locations is no longer valid and thus the pixel locations are not valid anymore either.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating an application that will have a list of items that can
I have been task with (ha) creating an application that will allow the users
I am creating an application that will have multiple images on the screen, these
Im creating application that will display remote page on the UIWebView using local images
I am creating a WPF application that will integrate with an existing system using
I'm creating an application that will store a hierarchical collection of items in an
I'm creating an application that will store geolocation data for specific transactions. Should I
I am creating a small application that will be deployed on Window. The database
I'm currently creating an MVC application that will likely to expand to include a
I am in the process of creating a java application that will be running

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.