0

when i added x and y coordinates to MapView.LayoutParams constructor. its MODE_VIEW behaviour disappears. I want this behaviour along with x and y coordinates. I am not getting the problem why this is happening.

public void addMarkerToMAp(GeoPoint geoPoint) {
    mapView.removeAllViews();

    final ImageView view = new ImageView(mapView.getContext());
    view.setImageResource(R.drawable.map_marker_anim);
    view.post(new Runnable() {
        @Override
        public void run() {
            AnimationDrawable animationDrawable = (AnimationDrawable) view.getDrawable();
            animationDrawable.start();
        }
    });

    mapView.addView(view);
    MapView.LayoutParams layoutParams = new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT,
        MapView.LayoutParams.WRAP_CONTENT,
        geoPoint,
        MapView.LayoutParams.MODE_VIEW);
    view.setLayoutParams(layoutParams);
}

So, I got the geoPoint as

geoPoint = mapView.getProjection().fromPixels((int)event.getX(), (int)event.getY()); where event is click event.

Also I want to show marker pin at (event.getX(), event.getY()), but it shows below the click.

yogesh
  • 11
  • 1

1 Answers1

0

If you code in eclipse, press ctrl+shift+f. That will make your code more readable. That being said, When you show a marker, which points do you use? If im not wrong then the point you will insert, will be the bottom left if its an overlay drawable.

topleft if its a view(i think thats what you are doing) and therefor it will appear under your click.

You can add an offsetx and offsety to it being -view.getWidth()/2 and -view.getHeight/2. which should then make your view directly centered under your pressed point. You might have trouble getting view.getWidth/Height though, so make sure it doesnt return 0.

Anders Metnik
  • 6,096
  • 7
  • 40
  • 79