マップビューの道路でバスアイコンを移動する方法が必要です。バスが通過する必要のあるすべての座標の経度と緯度のポイントを含むGeoPoint配列があります。また、ルートに沿って「変位アニメーション」を作成する必要があります。
オーバーレイクラスを使用して、1秒ごとにバスアイコンを設定します
class BusOverlay extends ItemizedOverlay<OverlayItem> {
private Context context = null;
private List<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
private MediaPlayer mediaPop;
public BusOverlay(Drawable defaultMarker, Context context) {
super(boundCenterBottom(defaultMarker));
this.context = context;
}
@Override
protected OverlayItem createItem(int i) {
return mOverlays.get(i);
}
@Override
public int size() {
return mOverlays.size();
}
public void addOverlayItem(OverlayItem overlayItem) {
mOverlays.add(overlayItem);
populate();
}
public void addOverlayItem(int lat, int lon, String title) {
GeoPoint point = new GeoPoint(lat, lon);
OverlayItem overlayItem = new OverlayItem(point, title, title);
addOverlayItem(overlayItem);
}
public void removeOverlay(OverlayItem overlay) {
mOverlays.remove(overlay);
populate();
}
public void removeOverlayItem(int lat, int lon, String title) {
GeoPoint point = new GeoPoint(lat, lon);
OverlayItem overlayItem = new OverlayItem(point, title, title);
removeOverlay(overlayItem);
}
protected boolean onTap(int index) {
super.onTap(index);
return true;
}
}
My Activityクラスで、Runableメソッドで使用しました
Drawable busLocationIcon = this.getResources().getDrawable(
R.drawable.bus_location);
final BusOverlay itemizedBusLocartionOverlay = new BusOverlay(
busLocationIcon, this);
int countBus = 0;
myRunnable = new Runnable() {
public void run() {
try {
itemizedBusLocartionOverlay.addOverlayItem((int) (Double
.parseDouble(Main.jsonArrayBus.getJSONObject(
countBus).getString("StopLat")) * 1000000),
(int) (Double.parseDouble(Main.jsonArrayBus
.getJSONObject(countBus).getString(
"StopLon")) * 1000000), "The Bus");
countBus++;
mapView.getOverlays().add(itemizedBusLocartionOverlay);
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//Hendler
h.postDelayed(myRunnable, 1000);
}
};
h.postDelayed(myRunnable, 1000);
しかし、それはうまく機能していません。
私を助けてください。