<p><img alt="" src="https://img-my.youkuaiyun.com/uploads/201205/09/1336566928_8704.jpg" /></p>package com.ui.overlay;
import android.content.Context;
import android.graphics.Canvas;
import android.view.GestureDetector;
import android.view.GestureDetector.OnDoubleTapListener;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import com.baidu.mapapi.GeoPoint;
import com.baidu.mapapi.MapView;
import com.baidu.mapapi.Overlay;
import com.ui.ShowMap;
public class LongClickOverlay extends Overlay implements OnDoubleTapListener, OnGestureListener {
private GestureDetector gestureScanner = new GestureDetector(this);
private Context mContext;
float x = 0;
float y = 0;
public LongClickOverlay(Context context) {
this.mContext = context;
}
@Override
public void draw(Canvas canvas, MapView mapView, boolean arg2) {
// TODO Auto-generated method stub
super.draw(canvas, mapView, arg2);
}
@Override
public boolean onTouchEvent(MotionEvent arg0, MapView arg1) {
return gestureScanner.onTouchEvent(arg0);
}
@Override
public void onLongPress(MotionEvent e) {
x = e.getX();
y = e.getY();
if (mContext instanceof ShowMap) {
((ShowMap) mContext).ShowPopuWindow((int) x, (int) y);
// ShowMap showMap = (ShowMap) mContext;
// MapView.LayoutParams geoLP = (MapView.LayoutParams)
// showMap.popView.getLayoutParams();
// geoLP.point = p;
// showMap.mapView.updateViewLayout(showMap.popView, geoLP);
// ((ShowMap) mContext).popView.setVisibility(View.VISIBLE);
}
}
@Override
public boolean onDown(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onShowPress(MotionEvent e) {
// TODO Auto-generated method stub
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onDoubleTap(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onDoubleTapEvent(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onTap(GeoPoint arg0, MapView arg1) {
return super.onTap(arg0, arg1);
}
}
- // 弹出窗口
- popView = getLayoutInflater().inflate(R.layout.popview, null);
- mapView.addView(popView, new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT,
- MapView.LayoutParams.WRAP_CONTENT, null, MapView.LayoutParams.BOTTOM_CENTER));
- popView.setVisibility(View.GONE);
- public void ShowPopuWindow(int x ,int y){
- GeoPoint p =mapView.getProjection().fromPixels(x, y);
- MapView.LayoutParams geoLP = (MapView.LayoutParams) popView.getLayoutParams();
- geoLP.point = p;
- mapView.updateViewLayout(popView, geoLP);
- popView.setVisibility(View.VISIBLE);
- mapView.invalidate();
- }