在此处缩放地图以显示所有标记 [英] Zoom HERE maps to show all markers Android

查看:88
本文介绍了在此处缩放地图以显示所有标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android应用中的HERE地图上显示了多个位置.全部4个标记中,其中3个标记在一个城市中,而1个标记在另一个城市中.当前,我的地图缩放到一个城市中只有3个标记可见而第4个标记不可见的级别.为了查看该标记,我必须缩小相当的水平.

I have multiple locations that I am displaying on HERE maps in my Android app. There are in all 4 markers, out of which 3 markers are in one city and 1 is in another city. Currently, my map zooms to a level where only the 3 markers in one city are visible, whereas the 4th one is not visible. In order to see that marker, I have to zoom out a considerable level.

有没有办法显示地图范围内的所有标记?

Is there a way, I can show all the markers within the bounds of the map?

这是我的代码:-

 m_map = mapFragment.getMap();
                m_map.setZoomLevel((m_map.getMaxZoomLevel() + m_map.getMinZoomLevel()) / 2);
                m_map.setMapScheme(Map.Scheme.NORMAL_DAY);

  final GeoCoordinate finalZoomLatLng = m_map.getCenter();
        new Handler().postDelayed(() -> {
            m_map.setCenter(finalZoomLatLng, Map.Animation.NONE);
            m_map.zoomTo(m_map.getBoundingBox(), Map.Animation.NONE, Map.MOVE_PRESERVE_ORIENTATION);
        }, 1000); 

编辑

借助Rahul的回答,我取得了类似的成就:-

With the help of Rahul's answer I have achieved something like so:-

for (int i = 0; i < tasks.size(); i++)
{
    final GeoCoordinate latLng = m_getPosition(tasks[i]);
    LatLng mLatLng = new LatLng(latLng.getLatitude(), latLng.getLongitude());
    mLatLngBounds.include(mLatLng);
}

GeoCoordinate finalZoomLatLng = new GeoCoordinate(mLatLngBounds.build().getCenter().latitude, mLatLngBounds.build().getCenter().longitude);
            new Handler().postDelayed(() -> {
                m_map.setCenter(finalZoomLatLng, Map.Animation.NONE);
                m_map.zoomTo(new GeoBoundingBox(finalZoomLatLng, 0.0f, 200000.0f), Map.Animation.NONE, Map.MOVE_PRESERVE_ORIENTATION);
            }, 1000);

现在,将地图放大到其中心及其周围所有位置.但是,此位置没有标记,因此我必须缩小一点以查看所有标记.我该如何解决?

Now with this, the map is zoomed in the center of the map with all the locations around it. However, there is no marker at this location, so I have to zoom out a bit to see all markers. How can I solve this?

我们非常感谢您的帮助.

Any help is highly appreciated.

推荐答案

使用此功能我也实现了同样的目的.

Same thing I achieved using this.

val geoCoordinateList = ArrayList<GeoCoordinate>()
val geoBoundingBox = GeoBoundingBox.getBoundingBoxContainingGeoCoordinates(geoCoordinateList)
map.zoomTo(geoBoundingBox, Map.Animation.LINEAR, Map.MOVE_PRESERVE_TILT)

这篇关于在此处缩放地图以显示所有标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆