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 9167999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:31:37+00:00 2026-06-17T15:31:37+00:00

I have a small android problem (google maps v2 api) This is my code:

  • 0

I have a small android problem (google maps v2 api)

This is my code:

GoogleMaps mMap;
Marker marker =  mMap.addMarker(new MarkerOptions().position(new LatLng(20, 20)));

I am trying to find a way to get the current screen coordinates (x,y) for this marker object.

Perhaps someone has an idea? I tried getProjection but it does not see to work.
Thanks! 🙂

  • 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-06-17T15:31:38+00:00Added an answer on June 17, 2026 at 3:31 pm

    Yes, use Projection class. More specifically:

    1. Get Projection of the map:

      Projection projection = map.getProjection();
      
    2. Get location of your marker:

      LatLng markerLocation = marker.getPosition();
      
    3. Pass location to the Projection.toScreenLocation() method:

      Point screenPosition = projection.toScreenLocation(markerLocation);
      

    That’s all. Now screenPosition will contain the position of the marker relative to the top-left corner of the whole Map container 🙂

    Edit

    Remember, that the Projection object will only return valid values after the map has passed the layout process (i.e. it has valid width and height set). You’re probably getting (0, 0) because you’re trying to access position of the markers too soon, like in this scenario:

    1. Create the map from layout XML file by inflating it
    2. Initialize the map.
    3. Add markers to the map.
    4. Query Projection of the map for marker positions on the screen.

    This is not a good idea since the the map doesn’t have valid width and height set. You should wait until these values are valid. One of the solutions is attaching a OnGlobalLayoutListener to the map view and waiting for layout process to settle. Do it after inflating the layout and initializing the map – for example in onCreate():

    // map is the GoogleMap object
    // marker is Marker object
    // ! here, map.getProjection().toScreenLocation(marker.getPosition()) will return (0, 0)
    // R.id.map is the ID of the MapFragment in the layout XML file
    View mapView = getSupportFragmentManager().findFragmentById(R.id.map).getView();
    if (mapView.getViewTreeObserver().isAlive()) {
        mapView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                // remove the listener
                // ! before Jelly Bean:
                mapView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                // ! for Jelly Bean and later:
                //mapView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                // set map viewport
                // CENTER is LatLng object with the center of the map
                map.moveCamera(CameraUpdateFactory.newLatLngZoom(CENTER, 15));
                // ! you can query Projection object here
                Point markerScreenPosition = map.getProjection().toScreenLocation(marker.getPosition());
                // ! example output in my test code: (356, 483)
                System.out.println(markerScreenPosition);
            }
        });
    }
    

    Please read through the comments for additional informations.

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

Sidebar

Related Questions

I have a small problem with android maps. I added an ItemizedOverlay class to
i am having a small problem with my android application. I have some mp3
I have small problem in android for Multichoice dialog box. I have done with
Just started working with android and ran into a small problem. I am have
I have a small problem with OrmLite on Android. When I increment the database
I have a small android problem, I have a requirement to have a timer
I am doing an contact list android application but i have a small problem
I am doing an contact list android application but i have a small problem
I have a small problem. I am testing my Android REST class on http://www.thomas-bayer.com/sqlrest/CUSTOMER
I have a small Android ImageButton on a screen representing an icon. The problem

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.