给定圆心和半径,如何在谷歌地图中获得圆的纬度边界? [英] How to get the LatLngBounds of a Circle in Google maps given its center and radius?

查看:28
本文介绍了给定圆心和半径,如何在谷歌地图中获得圆的纬度边界?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获得给定中心和半径的圆的东北和西南坐标?我在任何地方都找不到任何解决方案.目前,与以前不同,Circle 对象没有 getLatLngBounds() 和 getBounds() 方法.

How can I get the Northeast and Southwest coordinates of a Circle with a given center and radius? I can't find any solution anywhere. Currently, the Circle object doesn't have getLatLngBounds() nor getBounds() methods unlike before.

推荐答案

您可以使用 SphericalUtil.computeOffset 方法从Google Maps Android API 实用程序库.要使用它,您需要对 build.gradle 有以下依赖:

You can use the SphericalUtil.computeOffset method from the Google Maps Android API Utility Library. To use it you need to the following dependency to your build.gradle:

dependencies {
    compile 'com.google.maps.android:android-maps-utils:0.4+'
}

然后,您可以计算圆的东北和西南坐标:

Then, you can calculate the northeast and southwest coordinates of your circle doing:

double radius = 104.52;
LatLng center = new LatLng(40.22861, -3.95567);

LatLng targetNorthEast = SphericalUtil.computeOffset(center, radius * Math.sqrt(2), 45);
LatLng targetSouthWest = SphericalUtil.computeOffset(center, radius * Math.sqrt(2), 225);

这篇关于给定圆心和半径,如何在谷歌地图中获得圆的纬度边界?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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