I have problem about google map.The part of my project i am trying to
adding pin to MapView.When project is begin everything is ok.I am
adding pin where i clicked on but when i moved the map and clicked
somewhere i can not adding pin.OnTouch event is not working?
Can anybody help me?
Code is here:
package com.example.mapviewballoons.example.custom;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import com.google.android.maps.*;
import java.util.List;
public class CustomMap extends MapActivity {
MapView mapView;
List<Overlay> mapOverlays;
Drawable drawable;
Drawable drawable2;
CustomItemizedOverlay<CustomOverlayItem> itemizedOverlay;
CustomItemizedOverlay<CustomOverlayItem> itemizedOverlay2;
private Projection projection;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
mapOverlays = mapView.getOverlays();
projection = mapView.getProjection();
final MapController mc = mapView.getController();
mc.setZoom(16);
mapView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent)
{
Log.e("Point
",Integer.toString(motionEvent.getPointerCount()));
if(motionEvent.getAction() == MotionEvent.ACTION_UP){
drawable =
getResources().getDrawable(R.drawable.marker);
itemizedOverlay = new
CustomItemizedOverlay<CustomOverlayItem>(drawable, mapView);
// GeoPoint point = new GeoPoint((int)
(motionEvent.getXPrecision()*1E6),(int)
(motionEvent.getYPrecision()*1E6));
GeoPoint p = mapView.getProjection().fromPixels(
(int) motionEvent.getX(),
(int) motionEvent.getY());
CustomOverlayItem overlayItem = new
CustomOverlayItem(p, "Tomorrow Never Dies (1997)",
"(M gives Bond his mission in Daimler
car)",
"http://ia.media-imdb.com/images/M/
MV5BMTM1MTk2ODQxNV5BMl5BanBnXkFtZTcwOTY5MDg0NA@@._V1._SX40_CR0,0,40,54_.jpg");
itemizedOverlay.addOverlay(overlayItem);
mapOverlays.add(itemizedOverlay);
mc.animateTo(p);
mapView.invalidate();
return true;
}
else
if(motionEvent.getAction()==MotionEvent.ACTION_MOVE)
{
return false;
}
return true; //To change body of implemented
methods use File | Settings | File Templates.
}
});
// first overlay
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en