TileProvider method getTile - need to translate x and y to lat/long

前端 未结 3 764
北荒
北荒 2020-12-08 11:12

I’m porting an iOS app to Android, and using Google Maps Android API v2. The application needs to draw a heatmap overlay onto the map.

So far, it looks

3条回答
  •  时光说笑
    2020-12-08 12:03

    MaciejGórski if you don't mind (if you do, I will remove this post) I compiled your code into ready to use method:

    private LatLngBounds boundsOfTile(int x, int y, int zoom) {
        int noTiles = (1 << zoom);
        double longitudeSpan = 360.0 / noTiles;
        double longitudeMin = -180.0 + x * longitudeSpan;
    
        double mercatorMax = 180 - (((double) y) / noTiles) * 360;
        double mercatorMin = 180 - (((double) y + 1) / noTiles) * 360;
        double latitudeMax = toLatitude(mercatorMax);
        double latitudeMin = toLatitude(mercatorMin);
    
        LatLngBounds bounds = new LatLngBounds(new LatLng(latitudeMin, longitudeMin), new LatLng(latitudeMax, longitudeMin + longitudeSpan));
        return bounds;
    }
    

提交回复
热议问题