简体   繁体   中英

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.

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. 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)

在此处输入图片说明

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.

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. 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();
        }
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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