1

我在我的应用程序上使用 google maps API 的第 1 版,顶部有自定义重叠。问题是,在很多情况下,我都会在应用程序上遇到崩溃和强制关闭,我很确定这是由地图引起的。我检查了线程,我意识到我需要使用 populate() 函数。

问题是我不确定在哪里使用它,因为代码不是我最初编写的:(。

03-27 10:53:09.440: E/InputEventReceiver(28709): Exception dispatching input event.
03-27 10:53:09.440: E/MessageQueue-JNI(28709): Exception in MessageQueue callback:     handleReceiveCallback
03-27 10:53:09.490: E/MessageQueue-JNI(28709): java.lang.NullPointerException
03-27 10:53:09.490: E/MessageQueue-JNI(28709):  at com.google.android.maps.ItemizedOverlay.getItemsAtLocation(ItemizedOverlay.java:617)
03-27 10:53:09.490: E/MessageQueue-JNI(28709):  at com.google.android.maps.ItemizedOverlay.getItemAtLocation(ItemizedOverlay.java:586)
03-27 10:53:09.490: E/MessageQueue-JNI(28709):  at com.google.android.maps.ItemizedOverlay.handleMotionEvent(ItemizedOverlay.java:498)
03-27 10:53:09.490: E/MessageQueue-JNI(28709):  at com.google.android.maps.ItemizedOverlay.onTouchEvent(ItemizedOverlay.java:572)
03-27 10:53:09.490: E/MessageQueue-JNI(28709):  at com.google.android.maps.OverlayBundle.onTouchEvent(OverlayBundle.java:63)
03-27 10:53:09.490: E/MessageQueue-JNI(28709):  at com.google.android.maps.MapView.onTouchEvent(MapView.java:681)
03-27 10:53:09.490: E/MessageQueue-JNI(28709):  at android.view.View.dispatchTouchEvent(View.java:7337)
03-27 10:53:09.490: E/MessageQueue-JNI(28709):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2410)
03-27 10:53:09.490: E/MessageQueue-JNI(28709):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2145)
03-27 10:53:09.490: E/MessageQueue-JNI(28709):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2416)
03-27 10:53:09.490: E/MessageQueue-JNI(28709):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2117)
03-27 10:53:09.490: E/MessageQueue-JNI(28709):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2416)
03-27 10:53:09.490: E/MessageQueue-JNI(28709):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2117)
03-27 10:53:09.490: E/MessageQueue-JNI(28709):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2416)
03-27 10:53:09.490: E/MessageQueue-JNI(28709):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2117)
03-27 10:53:09.490: E/MessageQueue-JNI(28709):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2416)
03-27 10:53:09.490: E/MessageQueue-JNI(28709):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2117)
03-27 10:53:09.490: E/MessageQueue-JNI(28709):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2416)
03-27 10:53:09.490: E/MessageQueue-JNI(28709):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2117)
03-27 10:53:09.490: E/MessageQueue-JNI(28709):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2416)

这是我的逐项叠加类,它造成了麻烦

public class AdvrItemizedOverlay extends ItemizedOverlay<MapOverlayItem> {

protected Vector<AdvrMapItem> mOverlayItems = new Vector<AdvrMapItem>();

protected Bitmap mEmptyMarker = null;

protected Resources mResources = null;

protected Rect mDstRect = new Rect(6, 6, 66, 66);

public AdvrItemizedOverlay(Resources res) {
    super(boundCenterBottom(res.getDrawable(R.drawable.bg_map_mark_adver)));
    mEmptyMarker = BitmapFactory.decodeResource(res, R.drawable.bg_map_mark_adver);
    float density = (float)mEmptyMarker.getWidth() / 72.0f;
    mDstRect.left *= density;
    mDstRect.top *= density;
    mDstRect.right *= density;
    mDstRect.bottom *= density;
    mResources = res;
    performPopulated();
}

@Override
protected MapOverlayItem createItem(int i) {
    AdvrMapItem advrItem = mOverlayItems.get(i);
    MapOverlayItem overlayItem = advrItem.overlayItem();
    Drawable marker = advrItem.mapMarker(mResources, mEmptyMarker, mDstRect);
    if (marker != null)
        overlayItem.setMarker(boundCenterBottom(marker));
    return overlayItem;

}

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

public void add(AdvrMapItem userItem) {
    mOverlayItems.add(userItem);
    populate();
}

public void remove(AdvrMapItem item) {
    mOverlayItems.remove(item);
    setLastFocusedIndex(-1);
    populate();
}

public void clear() {
    mOverlayItems.removeAllElements();
    setLastFocusedIndex(-1);
    populate();
}

public void performPopulated() { populate(); }

}

我不确定何时调用构造函数以及放置填充方法的位置。谢谢大家

4

1 回答 1

0

你在某个时候给它传递了一个空标记。你需要找出在哪里。您可能还需要考虑更新 - 不仅版本 2 中的 API 更简单,而且他们不再分发新的 v1 api 密钥/

于 2013-03-27T04:43:43.903 回答