Issue
I would like to convert a GeoPoint to a screen point in order to identify all objects which are above a touch event. So, I've tried this :
Projection projection = this.mapView.getProjection();
GeoPoint gie = new GeoPoint(lat, lon);
Point po = new Point();
projection.toPixels(gie, po);
But, po.x and po.y are not the screen coords, but the mapview coords in pixel instead of lat,lon.
From the android developer website :
toPixels(GeoPoint in, android.graphics.Point out) Converts the given GeoPoint to onscreen pixel coordinates, relative to the top-left of the MapView that provided this Projection.
So, is it possible to convert it in the correct screen coords ?
I want to know all the x GeoPoint which are next to the + touch event like on the example above :
----------------------------------------------------------------
(0,0) -----------> x |
| |
| |
| | <-- My screen
| + (touch event) |
\/ x (my GeoPoint) |
y |
|
----------------------------------------------------------------
I get the touch event like that :
@Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
float y = event.getY();
Here, in this code, x and y are the real screen coords (the hardware ones, not the mapview ones)
I know that I can also convert x,y screen coordinates in GeoPoint to compare them to my GeoPoint, but, because of the zoom level, I can't get what I want.
Solution
I've found a solution, I don't know if it's the best way to get it, but it works!
I've found thank to your help @nickt, the method getScreenRect() which return the current bounds of the screen in screen coordinates.
Here the code :
float pisteX;
float pisteY;
Projection projection = this.mapView.getProjection();
Point pt = new Point();
GeoPoint gie = new GeoPoint(latitude,longitude);
Rect rec = mapView.getScreenRect(new Rect());
projection.toPixels(gie, pt);
pisteX = pt.x-rec.left; // car X screen coord
pisteY = pt.y-rec.top; // car Y screen coord
Answered By - Bibu
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.