简体   繁体   English

Android-具有以米为单位的固定半径的Google Maps API Heatmap

[英]Android - Google Maps API Heatmap with fixed radius in meters

The Heatmap Overlay for the Android Google Maps API renders the radius in pixels, which means that by zooming in and out the radius gets bigger and smaller. 适用于Android Google Maps API的Heatmap叠加层以像素为单位渲染半径,这意味着通过放大和缩小半径会越来越大。

I need a heatmap with fixed radius (eg in meters instead of pixels) that does not rescale when zooming in and out. 我需要一个固定半径的热图(例如,以米为单位而不是像素),并且在放大和缩小时都不会重新缩放。

Is there any possibility to do so? 有可能这样做吗?

In googlemap api, get scale data. 在googlemap API中,获取比例数据。 In UI you have the legend which states the map scale. 在用户界面中,您可以看到说明地图比例的图例。 Something like this - (check in google maps bottom right I'm talking about 2000Ft thing below) 像这样的东西-(在Google Maps右下角查看,我在下面谈论2000Ft之类的东西)

在此处输入图片说明

You know cm length of the phone screen, you know the pixels in complete width,so 您知道手机屏幕的厘米长度,知道完整宽度的像素,所以

cm(phoneScreen) --> cm/pixel ratio --> pixel radius to cm radius. cm(phoneScreen)-> cm /像素比->像素半径到cm半径。

you can deduce using some maths I suppose. 你可以用我想的一些数学来推论。

As for my opinion you can use setRadius() method to change the radius of heatmaps location in response to changed zoom. 我认为您可以使用setRadius()方法来更改热图位置的半径,以响应更改的缩放比例。 Something like this: 像这样:

    int DEFAULT_ZOOM_LEVEL = 10;
    int ZOOM_STEP_FOR_RADIUS = 2;

    mProvider = new HeatmapTileProvider.Builder()
            .data(mList)
            .setRadius(DEFAULT_ZOOM_LEVEL)
            .build();
    mOverlay = mMap.addTileOverlay(new TileOverlayOptions().tileProvider(mProvider));

    mMap.setOnCameraIdleListener(new GoogleMap.OnCameraIdleListener({
        @Override
        void onCameraIdle() {
            float newZoom = mMap.getCameraPosition().zoom;

            mProvider.setRadius(DEFAULT_ZOOM_LEVEL + newZoom * ZOOM_STEP_FOR_RADIUS)
            mOverlay.clearTileCache();
        }
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM