2

I have an activity that extends MapActivity, and inside onCreate() I have this code

 GeoPoint point = new GeoPoint((int)(1.3*1E6),(int)(34.45*1E6)); 
 final MapController mc;
 mc.animateTo(point);

that animates, to that point, however, when it animates, the point is in the center of the screen, and I want it to be in a fixed (X,Y) position on the screen. Is there an mc.animatetoLeftBottom(point) function?

Edit : I used the Projection p = mapView.getProjection(); point = p.fromPixels(50, 60); mc.animateTo(point);

pictures: When I start the app, it looks like this :

initial

After I tap once on the pin, it looks like this

after one tap

And, if I tap again on the pin, it will look like this:

after two taps

This is how it should look like, no matter where I tap it from, or if I scroll, zoom and then tap again:

how it should be

What I want is for it to automatically move to that position(see last picture) when I tap the pin

WendiKidd
  • 4,333
  • 4
  • 33
  • 50
Ovidiu Birgu
  • 439
  • 2
  • 6
  • 24

2 Answers2

3

Can't you just change the GeoPoint to account for the fact, and animate to a different point?

joey
  • 578
  • 4
  • 10
  • 2
    I think you miss understood the question, I was referring to moving the view, not the actual point when the user presses it. Even if I put a different point when I click it, it will still go to the center. The reason why I don't want it in the center is because when I click the pin, a balloon pops up and part of it can't be seen (this problem occurs on small res screens) – Ovidiu Birgu May 24 '11 at 14:08
  • I was suggesting that you centre the map on a different point, that will actually position the point you want in the bottom left. – joey May 24 '11 at 16:10
  • 2
    yes, but how do I center the map? also, I have more than 1000 pins – Ovidiu Birgu May 24 '11 at 16:26
  • got it working :D I create a new point, and then substract a value from the latitude and longitude and then I animate to that point GeoPoint pointHelper = new GeoPoint(point.getLatitudeE6()-(int)(0.001*1E6), point.getLongitudeE6() -(int)(0.001*1E6)); mc.animateTo(pointHelper); – Ovidiu Birgu May 24 '11 at 16:33
  • 2
    why doesn't it work anymore when I zoom out ? If I zoom back at that level it positions right, and if I zoom in it moves too much to the left – Ovidiu Birgu May 24 '11 at 16:55
  • When you zoom out, the amount you have to "shift" the `GeoPoint` by will have to change too. – joey May 26 '11 at 10:19
  • 2
    yes, I solved it, I had to multiply with a value that was connected to the zoom level – Ovidiu Birgu May 26 '11 at 16:00
2

Try this:

MapView mv = getMapView(); // fetch your map view
Projection p = mv.getProjection(); 
GeoPoint point = p.fromPixels(X, Y);
mc.animateTo(point);
Femi
  • 64,273
  • 8
  • 118
  • 148
  • 2
    the position moves, but randomly, I want it to move to a fixed position on the screen when I click it, for example: if the pin is in the right corner of the screen or in the center(vertically and horizontally) of the screen, when I click it, it will move the screen to the left bottom corner. – Ovidiu Birgu May 24 '11 at 14:04
  • 2
    I'm not sure I entirely understand what you are looking for, but the best control you have is the ability to specify the center of the map. So your task is to figure out what the center should be that sets the map to show what you'd like. The map CAN'T move randomly: it will center on whatever X and Y you specify. If you need to apply an offset (so the map places that point in the bottom left) then add/subtract an offset, right? – Femi May 24 '11 at 14:14
  • 2
    could you please tell me what those X,Y should do? are they moving the position of the view with X px to the left and Y px to the bottom? For ex: if the pin is at the position (40, 80) and X=10 and Y=20 then when I click the pin the view will move to (50, 90) ? – Ovidiu Birgu May 24 '11 at 14:36
  • 2
    If I call (without using the projection methode) mc.animateTo(point); and then mapView.scrollTo(50, 70);, it goes to that exact position on the screen, but I can't tap again on the pin and the balloon will inflate only if I tap on the center of the screen, also the mapView doesn't redraw properly, there are black lines on the left and bottom – Ovidiu Birgu May 24 '11 at 16:06