首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >气泡弹出框

气泡弹出框
EN

Stack Overflow用户
提问于 2011-12-11 18:40:31
回答 3查看 2.3K关注 0票数 1

谷歌地图,它允许我们定位任何我们想要的位置。在定位后,在图钉的顶部会有一个“气泡”弹出框。我可以知道怎么做弹出窗口框吗?有要显示的代码吗?我现在正在使用警告对话框,但我希望它是“气泡”弹出窗口。

代码语言:javascript
复制
List<Overlay> mapOverlays = mapView.getOverlays();
        MapOverlay mapOverlay = new MapOverlay();

        mapOverlays.add(mapOverlay);

        // obtain gps location
        lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

        locationListener = new MyLocationListener();

        lm.requestLocationUpdates(
        // LocationManager.GPS_PROVIDER,
                LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
    }

    private class MyLocationListener implements LocationListener {

        @Override
        public void onLocationChanged(Location loc) {

            k = new GeoPoint((int) (loc.getLatitude() * 1E6),
                    (int) (loc.getLongitude() * 1E6));
            mc.animateTo(k);
            mc.setZoom(18);

            // Add a location marker
            MapOverlay mapOverlay = new MapOverlay();
            List<Overlay> listofOverlays = mapView.getOverlays();
            listofOverlays.clear();
            listofOverlays.add(mapOverlay);

            // invalidate() method forces the MapView to be redrawn
            mapView.invalidate();
        }

        @Override
        public void onProviderDisabled(String provider) {
        }

        @Override
        public void onProviderEnabled(String provider) {
        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
        }
    }

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

    class MapOverlay extends com.google.android.maps.Overlay {

        @Override
        public boolean onTap(final GeoPoint p, MapView mapView) {
            // TODO Auto-generated method stub

            k = p;
            mc = mapView.getController();
            mc.animateTo(p);

            mapView.invalidate();

            Geocoder geoCoder = new Geocoder(getBaseContext(),
                    Locale.getDefault());
            try {
                List<Address> addresses = geoCoder.getFromLocation(
                        p.getLatitudeE6() / 1E6, p.getLongitudeE6() / 1E6, 1);
                String add = "";
                if (addresses.size() > 0) {
                    for (int i = 0; i < addresses.get(0)
                            .getMaxAddressLineIndex(); i++)
                        add += addresses.get(0).getAddressLine(i) + "\n";
                    txtAddress.setText("Address: " + add);
                }
@Override
        public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
                long when) {
            super.draw(canvas, mapView, shadow);
            if (k != null) {
                // ---translate the GeoPoint to screen pixels---
                Point screenPts = new Point();
                mapView.getProjection().toPixels(k, screenPts);

                // ---add the marker---
                Bitmap bmp = BitmapFactory.decodeResource(getResources(),
                        R.drawable.passenger);
                canvas.drawBitmap(bmp, screenPts.x, screenPts.y - 50, null);
            }
            return true;
        }
    }
}
EN

回答 3

Stack Overflow用户

发布于 2011-12-15 02:34:54

我目前正在开发一个地图应用程序,其中我也需要显示'Bubble‘弹出窗口,下面的博客帖子对我有很大帮助。

This post from the Android Developers blog解释了什么是9补丁镜像以及如何创建一个。

使用这两个帖子,我能够将一些代码放在一起,它们工作得很好,所以希望你也能操作它来满足你的需求。

票数 1
EN

Stack Overflow用户

发布于 2011-12-11 18:59:13

听起来你在找InfoWindow。顺便说一句,在新版本的API中,它们没有圆角(它们看起来更像盒子,而不像气泡)。您可以通过在加载地图API的javascript URL中请求API的以前版本来恢复旧版本。

票数 0
EN

Stack Overflow用户

发布于 2012-03-05 06:11:13

谷歌并没有提供这样的应用程序接口,看看this吧。维克多的回答给出了一个符合要求的开源代码链接。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8463347

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档