使多边形垂直于谷歌地图的Andr​​oid轴承 [英] Make polygons perpendicular to bearing in google maps android

查看:263
本文介绍了使多边形垂直于谷歌地图的Andr​​oid轴承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在地图上创建多边形

 getMap().addPolygon(
            getPolygonOptions(point1, point2, widthInMeters)
                    .fillColor(Color.YELLOW));

的角的位置由计算:

The position of the corners is calculated by:

public static PolygonOptions getPolygonOptions(LatLng point1, LatLng point2, double widthInMeters) {


    double distance  = SphericalUtil.computeDistanceBetween(point1, point2) + 6;

   float bearing = location.getBearing();

    double bears = bearing;


    LatLng corner1 = SphericalUtil.computeOffset(point2, widthInMeters / 2, bears + 90);
    LatLng corner2 = SphericalUtil.computeOffset(point2, widthInMeters / 2, bears - 90);
    LatLng corner3 = SphericalUtil.computeOffset(corner2, distance, bears);
    LatLng corner4 = SphericalUtil.computeOffset(corner1, distance, bears);

    return new PolygonOptions().add(corner1, corner2, corner3, corner4);
}

其目的是为多边形垂直于所述轴承。在地图上的某些方向上的多边形几乎是这样,但你可以在这个图片中看到,在某些方向的多边形最终倾斜相比,目前的轴承。目前的轴承是由蓝色箭头和品红色折线图所示。任何人都可以找出什么毛病我的角落计算?

The intent was for the polygons to be perpendicular to the bearing. Certain directions on the map the polygons are nearly that way, but as you can see in this picture, in some directions the polygons end up slanted compared to the current bearing. The current bearing is shown by the blue arrow and the magenta polyline. Can anyone identify whats wrong with my corner calculations?

推荐答案

这可能是这是从两个函数返回单位的问题。

It may be problem of units which are returning from two functions.

下面,SphericalUtil.computeDistanceBetween(点1,点2)返回米的值。

Here, SphericalUtil.computeDistanceBetween(point1, point2) returns the values in meters.

谷歌的位置文档建议,

location.getBearing()以度返回值。

location.getBearing() returns values in degrees.

获取轴承,以度。
轴承是这个装置的行程的水平方向,并且是不相关的设备的方向。它被保证是在范围(0.0,360.0]如果设备有一个轴承

Get the bearing, in degrees. Bearing is the horizontal direction of travel of this device, and is not related to the device orientation. It is guaranteed to be in the range (0.0, 360.0] if the device has a bearing.

如果此位置不具有轴承则返回0.0

If this location does not have a bearing then 0.0 is returned.

请检查该位置是否搏动着轴承PR不使用location.getBearing前()

Please, check whether the location is heaving bearing pr not before using location.getBearing()

所以,你有这些转换成度米,然后实现它在你的逻辑。这将解决您的问题。

So, you have convert those degrees into meters and then implement it in your logic. It will solve your issue.

这篇关于使多边形垂直于谷歌地图的Andr​​oid轴承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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