我需要将我current location
的Marker
始终显示Google Map
为正在使用ItemizedOverlay
,但是每当我运行以下代码时,如果我将位置从. 下面是我的代码。我做错了什么吗?DDMS
public class MainActivity extends MapActivity {
private MyItemizedOverlay myItemizedOverlay = null;
private LocationManager locationManager = null;
private MapView mapView = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mapView = (MapView) findViewById(R.id.mapView);
mapView.setBuiltInZoomControls(true);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
0, new GeoUpdateHandler());
}
public class GeoUpdateHandler implements LocationListener {
@Override
public void onLocationChanged(Location location) {
int lat = (int) (location.getLatitude() * 1E6);
int lng = (int) (location.getLongitude() * 1E6);
Drawable marker=getResources().getDrawable(android.R.drawable.star_big_on);
int markerWidth = marker.getIntrinsicWidth();
int markerHeight = marker.getIntrinsicHeight();
marker.setBounds(0, markerHeight, markerWidth, 0);
myItemizedOverlay = new MyItemizedOverlay(marker);
mapView.getOverlays().add(myItemizedOverlay);
GeoPoint point = new GeoPoint(lat, lng);
//GeoPoint myPoint1 = new GeoPoint((int) (37.347184*1000000), (int) (-121.966551*1000000));
myItemizedOverlay.addItem(point, "myPoint1", "myPoint1");
mapController.animateTo(point);
String address = ConvertPointToLocation(point);
Toast.makeText(getBaseContext(), address, Toast.LENGTH_SHORT).show();
mapView.invalidate();
}
}
下边是MyItemizedOverlay class
public class MyItemizedOverlay extends ItemizedOverlay<OverlayItem>{
private ArrayList<OverlayItem> overlayItemList = new ArrayList<OverlayItem>();
public MyItemizedOverlay(Drawable marker) {
super(boundCenterBottom(marker));
// TODO Auto-generated constructor stub
populate();
}
public void addItem(GeoPoint p, String title, String snippet){
OverlayItem newItem = new OverlayItem(p, title, snippet);
overlayItemList.add(newItem);
populate();
}
@Override
protected OverlayItem createItem(int i) {
// TODO Auto-generated method stub
return overlayItemList.get(i);
}
@Override
public int size() {
// TODO Auto-generated method stub
return overlayItemList.size();
}
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
// TODO Auto-generated method stub
super.draw(canvas, mapView, shadow);
//boundCenterBottom(marker);
}
}
因为我还需要在 Google Maps 上显示其他标记,所以这就是我使用 ItemizedOverlay 概念的原因。ItemizedOverlay
首先,每当我的应用程序启动时,我需要专注于我当前的位置。对我的示例的任何建议将不胜感激。