import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.view.MotionEvent;
import android.widget.Toast;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
class MarkerOverlay extends Overlay{
private GeoPoint p;
public MarkerOverlay(GeoPoint p){
this.p = p;
}
public boolean onTouchEvent(MotionEvent event, MapView mapView) {
if (event.getAction() == 1) {
GeoPoint p = mapView.getProjection().fromPixels(
(int) event.getX(),
(int) event.getY());
Toast.makeText(getBaseContext(),
p.getLatitudeE6() / 1E6 + "," +
p.getLongitudeE6() /1E6 ,
Toast.LENGTH_SHORT).show();
mapView.getOverlays().add(new MarkerOverlay(p));
mapView.invalidate();
}
return false;
}
private Context getBaseContext() {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean draw(Canvas canvas, MapView mapView,
boolean shadow, long when){
super.draw(canvas, mapView, shadow);
//---translate the GeoPoint to screen pixels---
Point screenPts = new Point();
mapView.getProjection().toPixels(p, screenPts);
//---add the marker---
Bitmap bmp = BitmapFactory.decodeResource(getResources(),getDrawable(R.drawable.marker)) ;
canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);
return true;
}
private int getDrawable(int marker) {
// TODO Auto-generated method stub
return 0;
}
private Resources getResources() {
// TODO Auto-generated method stub
return null;
}
}
1 Replies - 2892 Views - Last Post: 28 March 2012 - 01:45 PM
#1
Itemized overlays add markers into mapview on double tap at
Posted 28 March 2012 - 01:38 PM
Replies To: Itemized overlays add markers into mapview on double tap at
#2
Re: Itemized overlays add markers into mapview on double tap at
Posted 28 March 2012 - 01:45 PM
Below is the code I am using to try to create markers dynamically to mapview. The mapview is in tab.
I get no errors it does nothing.
Thank you for any help
Mike
I get no errors it does nothing.
Thank you for any help
Mike
Page 1 of 1
|
|

New Topic/Question
Reply


MultiQuote



|