写一个类继承ItemizedOverlay
package cn.fn;

import java.util.ArrayList;
import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class CustomItemizedOverlay extends ItemizedOverlay<OverlayItem> {

private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>();
private Context context;

public CustomItemizedOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}

public CustomItemizedOverlay(Drawable defaultMarker, Context context) {
this(defaultMarker);
this.context = context;
}

@Override
protected OverlayItem createItem(int i) {
return mapOverlays.get(i);
}

@Override
public int size() {
return mapOverlays.size();
}

@Override
protected boolean onTap(int index) {
OverlayItem item = mapOverlays.get(index);
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.show();
return true;
}

public void addOverlay(OverlayItem overlayItem) {
mapOverlays.add(overlayItem);
this.populate();
}

}


MainActivity 取MapView 进行设置

package cn.fn;

import java.util.List;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;


public class TextActivity extends MapActivity {

private MapView mapView;

private static final int lat1 = 39984881;
private static final int lon1 = 116337044;

private static final int lat2 = 39977293;
private static final int lon2 = 116353089;

@Override
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.main);

mapView = (MapView) findViewById(R.id.myMapView);
mapView.setStreetView(true);
mapView.setTraffic(true);
mapView.setBuiltInZoomControls(true);

List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.hua);
CustomItemizedOverlay itemizedOverlay = new CustomItemizedOverlay(drawable, this);

itemizedOverlay.addOverlay(new OverlayItem(new GeoPoint(lat1, lon1), "HaHa", "HaHa"));
itemizedOverlay.addOverlay(new OverlayItem(new GeoPoint(lat2, lon2), "HaHa", "HaHa"));
mapOverlays.add(itemizedOverlay);

MapController mapController = mapView.getController();
//定位到显示的位置
mapController.animateTo(new GeoPoint(locallat, locallon));
mapController.setZoom(15);

}

@Override
protected boolean isRouteDisplayed() {
return false;
}

}



提示:这个现在还有一个问题就是加太多的话就会

更多相关文章

  1. android: content URI的真实路径获取
  2. android列表为空时提示语
  3. android location 位置定位
  4. android中Notification的使用
  5. Android中退出程序的提示框
  6. android百度定位
  7. Android入门:Button
  8. Android中如何使用对话框(单选对话框和多选对话框)
  9. Android之应用程序监听开机启动自启动应用程序

随机推荐

  1. Android在listview添加checkbox实现单选
  2. Android(安卓)中文API (94) —— MediaCont
  3. Android数据库工具ORM-greenDAO学习
  4. android6.0 状态栏添加图标 举例Location
  5. Android(安卓)开源项目
  6. Android(安卓)下拉刷新控件的使用
  7. Android(安卓)横竖屏切换的Activity生命
  8. Android日常知识收集与总结之Android的Di
  9. 【Android(安卓)开发教程】屏幕方向的改
  10. android默认debug.keystore的密码