1

I have two pairs of lat long values

currLat = 19.12696395;
currLong = 72.87338733;
collCurrLat = 19.12238216;
collCurrLong = 72.875275605;

I want to plot currLat and currLong at the center of the screen and collCurrLat and collCurrLong at location relative to it on the screen by depicting collCurrLat and collCurrLong as a small circle.

        int x = ((MapView)mParent).getWidth()/2;
        int y = ((MapView)mParent).getHeight()/2;

        //LatLonToPixel takes lat , long and zoom level as parameters.
        cPoint cpt = GlobalMercator.LatLonToPixel(currLat, currLong, 16);
        cPoint cptColl = GlobalMercator.LatLonToPixel(collCurrLat, collCurrLong, 16);

        int testx = cptColl.cx-cpt.cx + x;
        int testy =  cptColl.cy-cpt.cy + y;

        canvas.drawCircle(testx,testy,smallradius, mSelectionBrush);

I tried the above code. But gives me random positions. Is this approach correct?

Kara
  • 6,115
  • 16
  • 50
  • 57
Angela Sim
  • 137
  • 1
  • 21

1 Answers1

0

In Your Question you have asked I want to plot currLat and currLong at the center of the screen So to get the Center of Screen, try this link & answer posted by Josef Pfleger. To get the Screen Height & Width try this Code.

If you want the the display dimensions in pixels you can use getSize:

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
 int height = size.y;

If you're not in an Activity you can get the default Display via WINDOW_SERVICE:

WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();

Before getSize was introduced (in API level 13), you could use the getWidth and getHeight methods that are now deprecated:

Display display = getWindowManager().getDefaultDisplay(); 
int width = display.getWidth();  // deprecated
int height = display.getHeight();  // deprecated

For the use case you're describing however a margin/padding in the layout seems more appropriate.

Hope this helps You.

Community
  • 1
  • 1
i.n.e.f
  • 1,773
  • 13
  • 22
  • Thanks inef, I cannot make use of the GoogleMap API..in my app and neither am I using Google map V2. Can you please let me know if my approach of finding the relative position of two lat longs scaled to screen size is valid? – Angela Sim Mar 13 '14 at 08:45
  • check my edited Code. To get the Center of Screen.Sorry i am unaware of GlobalMercator Class. :( So i am not able to judge your code.But try the edited Code.Hope the code will help you. – i.n.e.f Mar 13 '14 at 09:23
  • Thanks Inef, i have the center of the screen with me in x, y coordinates the variables (x and y) i have mentioned in my code snippet. What i am not able to understand is the way to correlate the lat long to the center. I mean, by what "factor" must I shift the lat long values to bring it to screen center? The size you are passing as parameter to getSize (), where are you introducing the lat long in the scheme of things? – Angela Sim Mar 13 '14 at 09:31