我是SD卡上的一些图像。我还保存了他们的经度和纬度。现在我想将所有这些图像覆盖在Google地图上作为缩略图...当我点击任何缩略图时,它将移动到下一个活动,如显示全图。我可以只打印一张图片......它的代码是......
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.googlemap);
mapView = (MapView) findViewById(R.id.mapView);
mapView.setBuiltInZoomControls(true);
// imm=(ImageView)findViewById(R.id.Google_Img_View);
mapView.setSatellite(true);
b=(Button)findViewById(R.id.googleImageDone);
b.setOnClickListener(this);
Intent i = getIntent();
//Parcelable myParcelableObject = (Parcelable) i.getParcelableExtra("name_of_extra");
bit = (Bitmap) getIntent().getParcelableExtra("Map");
//imm.setImageBitmap(bit);
String id = i.getStringExtra("lon");
String name = i.getStringExtra("long");
// mapView.setTraffic(true);
mc = mapView.getController();
String coordinates[] = {id,name};
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
pp = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
mc.animateTo(pp);
mc.setZoom(19);
MapOverlay mapOverlay = new MapOverlay();
List<Overlay> listOfOverlays = mapView.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(mapOverlay);
}
private class MapOverlay extends Overlay
{
@Override
public boolean draw(Canvas canvas, MapView mapView,
boolean shadow, long when)
{
super.draw(canvas, mapView, shadow);
Point screenPts = new Point();
//---translate the GeoPoint to screen pixels---
mapView.getProjection().toPixels(pp, screenPts);
//---convert the gif image into bmp
// Bitmap bmp = BitmapFactory.decodeResource(
// getResources(), R.drawable.e);
//---add the marker---
canvas.drawBitmap(bit, screenPts.x, screenPts.y-50, null);
return true;
}
@Override
public boolean onTouchEvent(MotionEvent event, MapView mapView)
{
if (event.getAction() == 1)
{
GeoPoint p = mapView.getProjection().fromPixels(
(int) event.getX(), (int) event.getY());
st1=p.getLatitudeE6() / 1E6+"";
st2=p.getLongitudeE6() /1E6+"";
Toast.makeText(getBaseContext(), "Location: "+
p.getLatitudeE6() / 1E6 + "," + p.getLongitudeE6() /1E6 ,
Toast.LENGTH_SHORT).show();
}
return false;
}
}
答案 0 :(得分:0)
创建一个类 -
public class HelloItemizedOverlay extends ItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
private Context mContext;
public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
super(boundCenterBottom(defaultMarker));
mContext = context;
}
public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
populate();
}
@Override
protected OverlayItem createItem(int i) {
return mOverlays.get(i);
}
@Override
public int size() {
return mOverlays.size();
}
@Override
protected boolean onTap(int index) {
OverlayItem item = mOverlays.get(index);
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.show();
return true;
}
为Latitute和Longitude转换创建另一个类 -
public class LatLonPoint extends GeoPoint {
public LatLonPoint(double latitude, double longitude) {
super((int) (latitude * 1E6), (int) (longitude * 1E6));
}
}
然后在你的主要活动中 -
mMapView = (MapView) findViewById(R.id.mv);
mMapView.setBuiltInZoomControls(true);
List<Overlay> mapOverlays = mMapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(
R.drawable.ic_launcher);
HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(
drawable, this);
GeoPoint point = new LatLonPoint(12.917745600000000000,
77.623788300000000000);
OverlayItem overlayitem = new OverlayItem(point, "Bangalore!",
"I'm in Silkboard!");
GeoPoint point2 = new LatLonPoint(12.8511803, 77.6635172);
OverlayItem overlayitem2 = new OverlayItem(point2, "Bangalore!",
"India, Somewhere!");
itemizedoverlay.addOverlay(overlayitem);
itemizedoverlay.addOverlay(overlayitem2);
mapOverlays.add(itemizedoverlay);
从SD卡读取图像 -
Resources res = getResources();
Bitmap bitmapICON = BitmapFactory.decodeFile("PATH OF THE IMAGE");
BitmapDrawable bdICON = new BitmapDrawable(res, bitmapICON);