如何向 android 地图视图添加另一个覆盖项目

发布于 2024-10-15 10:41:17 字数 3346 浏览 8 评论 0原文

我需要向地图视图添加另一个覆盖项目。我已经使用了谷歌地图的标准 Android 开发人员指南。我目前在选项卡中有地图视图。我真的很感激任何想法。谢谢。

下面是我的 java 类:

public class Mapview extends MapActivity {

    protected boolean isRouteDisplayed(){
        return false;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mapview);

        MapView mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);

        // JD sports marker begin
        List<Overlay> mapOverlays = mapView.getOverlays();
        Drawable drawable = this.getResources()
                .getDrawable(R.drawable.jd_sports_logo);
        //Passes drawable(jd sports logo) into HelloItemizedOverlay class
        HelloItemizedOverlay itemizedoverlay = 
                new HelloItemizedOverlay(drawable);

        double latitude = 51.545538;
        double longitude = -0.477247;
        GeoPoint point = new GeoPoint((int)(latitude * 1e6), 
                (int)(longitude * 1e6));

        OverlayItem overlayitem = new OverlayItem(point, "JD Sports", 
                "This is a sports shop");

        itemizedoverlay.addOverlay(overlayitem);
        mapOverlays.add(itemizedoverlay);
        // JD sports marker ends

        // Fitness first marker begin
        List<Overlay> mapOverlays1 = mapView.getOverlays();
        Drawable drawable1 = this.getResources()
                .getDrawable(R.drawable.fitness_first_logo);
        HelloItemizedOverlay itemizedoverlay1 = 
                new HelloItemizedOverlay(drawable);

        double latitude1 = 51.545157;
        double longitude1 = -0.477247;
        GeoPoint point1 = new GeoPoint((int)(latitude * 1e6), 
                (int)(longitude * 1e6));

        OverlayItem overlayitem1 = new OverlayItem(point, "JD Sports",
                "This is a sports shop");

        itemizedoverlay.addOverlay(overlayitem);
        mapOverlays.add(itemizedoverlay);
        // Fitness first marker ends
    }

}

我的 HelloItemizedOverlay 类:

public class HelloItemizedOverlay extends ItemizedOverlay {

    private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
    private ArrayList<OverlayItem> mOverlays1 = new ArrayList<OverlayItem>();

    public HelloItemizedOverlay(Drawable defaultMarker) {
        super(boundCenterBottom(defaultMarker));

    }

    public void addOverlay(OverlayItem overlay) {

        mOverlays.add(overlay);
        populate();
    }

    public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
        super(defaultMarker);
        Context mContext = context;
    }

    @Override
    protected OverlayItem createItem(int i) {
        // TODO Auto-generated method stub
        return mOverlays.get(i);
    }

    @Override
    public int size() {
        // TODO Auto-generated method stub
        return mOverlays.size();
    }

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

}

I need to add another overlay item to a mapview. I have used the standard android developers guide to google maps. I currently have the mapview within a tab. I would really appreciate any ideas. Thanks.

Below are my java classes:

public class Mapview extends MapActivity {

    protected boolean isRouteDisplayed(){
        return false;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mapview);

        MapView mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);

        // JD sports marker begin
        List<Overlay> mapOverlays = mapView.getOverlays();
        Drawable drawable = this.getResources()
                .getDrawable(R.drawable.jd_sports_logo);
        //Passes drawable(jd sports logo) into HelloItemizedOverlay class
        HelloItemizedOverlay itemizedoverlay = 
                new HelloItemizedOverlay(drawable);

        double latitude = 51.545538;
        double longitude = -0.477247;
        GeoPoint point = new GeoPoint((int)(latitude * 1e6), 
                (int)(longitude * 1e6));

        OverlayItem overlayitem = new OverlayItem(point, "JD Sports", 
                "This is a sports shop");

        itemizedoverlay.addOverlay(overlayitem);
        mapOverlays.add(itemizedoverlay);
        // JD sports marker ends

        // Fitness first marker begin
        List<Overlay> mapOverlays1 = mapView.getOverlays();
        Drawable drawable1 = this.getResources()
                .getDrawable(R.drawable.fitness_first_logo);
        HelloItemizedOverlay itemizedoverlay1 = 
                new HelloItemizedOverlay(drawable);

        double latitude1 = 51.545157;
        double longitude1 = -0.477247;
        GeoPoint point1 = new GeoPoint((int)(latitude * 1e6), 
                (int)(longitude * 1e6));

        OverlayItem overlayitem1 = new OverlayItem(point, "JD Sports",
                "This is a sports shop");

        itemizedoverlay.addOverlay(overlayitem);
        mapOverlays.add(itemizedoverlay);
        // Fitness first marker ends
    }

}

My HelloItemizedOverlay class:

public class HelloItemizedOverlay extends ItemizedOverlay {

    private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
    private ArrayList<OverlayItem> mOverlays1 = new ArrayList<OverlayItem>();

    public HelloItemizedOverlay(Drawable defaultMarker) {
        super(boundCenterBottom(defaultMarker));

    }

    public void addOverlay(OverlayItem overlay) {

        mOverlays.add(overlay);
        populate();
    }

    public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
        super(defaultMarker);
        Context mContext = context;
    }

    @Override
    protected OverlayItem createItem(int i) {
        // TODO Auto-generated method stub
        return mOverlays.get(i);
    }

    @Override
    public int size() {
        // TODO Auto-generated method stub
        return mOverlays.size();
    }

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

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

流绪微梦 2024-10-22 10:41:17
OverlayItem overlayitem1 = new OverlayItem(point, "JD Sports, ...

应该读

OverlayItem overlayitem1 = new OverlayItem(point1, "JD Sports", ...

不是吗?

OverlayItem overlayitem1 = new OverlayItem(point, "JD Sports, ...

Should read

OverlayItem overlayitem1 = new OverlayItem(point1, "JD Sports", ...

Shouldn't it?

假装不在乎 2024-10-22 10:41:17

试试这个:

...
Drawable drawable1 = this.getResources()
            .getDrawable(R.drawable.fitness_first_logo);
boundCenterBottom(drawable1);
...

Try this:

...
Drawable drawable1 = this.getResources()
            .getDrawable(R.drawable.fitness_first_logo);
boundCenterBottom(drawable1);
...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文