【问题标题】:Bubble pop up box气泡弹出框
【发布时间】:2012-03-05 06:11:12
【问题描述】:

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

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;
        }
    }
}

【问题讨论】:

    标签: android google-maps


    【解决方案1】:

    我目前正在开发一个地图应用程序,我还需要显示“气泡”弹出窗口,以下博客文章对我帮助很大。

    This first post 展示了如何使用嵌入在视图中的 9-patch 图像来生成弹出窗口。代码没问题,但确实留下了许多未回答的问题,一些评论者要求提供一些额外的源代码以进行澄清。

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

    使用这两个帖子,我能够将一些运行良好的代码组合在一起,因此希望您也能够对其进行操作以满足您的需求。

    【讨论】:

    • 只是对此的更新 - 第一篇文章在我自己的博客上,我现在添加了一个指向完整源代码的链接,以防在任何时候帮助任何人。
    • 感谢更新 - 和来源,我发现这篇文章真的很有帮助。
    【解决方案2】:

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

    【讨论】:

    【解决方案3】:

    Google 不提供执行此操作的 API,请查看 this。 Victor 的回答提供了一个符合要求的开源代码链接。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-10
      相关资源
      最近更新 更多