栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Google Map API V2调整大小屏幕以匹配绘制的圆圈

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Google Map API V2调整大小屏幕以匹配绘制的圆圈

如果我理解正确,您是否希望地图适合圆形边界?如果是这样的话

像这样加一个圆

mMap.addCircle(new CircleOptions()        .center(new LatLng(location.getLatitude(), location.getLongitude()))        .radius(100)        .strokeColor(Color.RED)        .fillColor(Color.BLUE));

那么您需要您的圆的边界框,请阅读此

LatLngBounds bounds = boundsWithCenterAndLatLngDistance(new LatLng(location.getLatitude(), location.getLongitude()),200,200);

并尝试

private static final double ASSUMED_INIT_LATLNG_DIFF = 1.0;private static final float ACCURACY = 0.01f;public static LatLngBounds boundsWithCenterAndLatLngDistance(LatLng center, float latDistanceInMeters, float lngDistanceInMeters) {    latDistanceInMeters /= 2;    lngDistanceInMeters /= 2;    LatLngBounds.Builder builder = LatLngBounds.builder();    float[] distance = new float[1];    {        boolean foundMax = false;        double foundMinLngDiff = 0;        double assumedLngDiff = ASSUMED_INIT_LATLNG_DIFF;        do { Location.distanceBetween(center.latitude, center.longitude, center.latitude, center.longitude + assumedLngDiff, distance); float distanceDiff = distance[0] - lngDistanceInMeters; if (distanceDiff < 0) {     if (!foundMax) {         foundMinLngDiff = assumedLngDiff;         assumedLngDiff *= 2;     } else {         double tmp = assumedLngDiff;         assumedLngDiff += (assumedLngDiff - foundMinLngDiff) / 2;         foundMinLngDiff = tmp;     } } else {     assumedLngDiff -= (assumedLngDiff - foundMinLngDiff) / 2;     foundMax = true; }        } while (Math.abs(distance[0] - lngDistanceInMeters) > lngDistanceInMeters * ACCURACY);        LatLng east = new LatLng(center.latitude, center.longitude + assumedLngDiff);        builder.include(east);        LatLng west = new LatLng(center.latitude, center.longitude - assumedLngDiff);        builder.include(west);    }    {        boolean foundMax = false;        double foundMinLatDiff = 0;        double assumedLatDiffNorth = ASSUMED_INIT_LATLNG_DIFF;        do { Location.distanceBetween(center.latitude, center.longitude, center.latitude + assumedLatDiffNorth, center.longitude, distance); float distanceDiff = distance[0] - latDistanceInMeters; if (distanceDiff < 0) {     if (!foundMax) {         foundMinLatDiff = assumedLatDiffNorth;         assumedLatDiffNorth *= 2;     } else {         double tmp = assumedLatDiffNorth;         assumedLatDiffNorth += (assumedLatDiffNorth - foundMinLatDiff) / 2;         foundMinLatDiff = tmp;     } } else {     assumedLatDiffNorth -= (assumedLatDiffNorth - foundMinLatDiff) / 2;     foundMax = true; }        } while (Math.abs(distance[0] - latDistanceInMeters) > latDistanceInMeters * ACCURACY);        LatLng north = new LatLng(center.latitude + assumedLatDiffNorth, center.longitude);        builder.include(north);    }    {        boolean foundMax = false;        double foundMinLatDiff = 0;        double assumedLatDiffSouth = ASSUMED_INIT_LATLNG_DIFF;        do { Location.distanceBetween(center.latitude, center.longitude, center.latitude - assumedLatDiffSouth, center.longitude, distance); float distanceDiff = distance[0] - latDistanceInMeters; if (distanceDiff < 0) {     if (!foundMax) {         foundMinLatDiff = assumedLatDiffSouth;         assumedLatDiffSouth *= 2;     } else {         double tmp = assumedLatDiffSouth;         assumedLatDiffSouth += (assumedLatDiffSouth - foundMinLatDiff) / 2;         foundMinLatDiff = tmp;     } } else {     assumedLatDiffSouth -= (assumedLatDiffSouth - foundMinLatDiff) / 2;     foundMax = true; }        } while (Math.abs(distance[0] - latDistanceInMeters) > latDistanceInMeters * ACCURACY);        LatLng south = new LatLng(center.latitude - assumedLatDiffSouth, center.longitude);        builder.include(south);    }    return builder.build();}

终于打电话

CameraUpdateFactory#newLatLngBounds(bounds, padding);


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/440065.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号