Google Maps SphericalUtil computeOffset [英] Google Maps SphericalUtil computeOffset

查看:193
本文介绍了Google Maps SphericalUtil computeOffset的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用google maps android库中SpericalUtil的computeOffset()。 computeOffset接受下列参数:

pre code public static LatLng computeOffset(LatLng from,double distance,double heading)

code>

以及前两个标记的原始坐标我可以使用computeOffset在输入距离和标题后生成另一行。我的目标是在相距一定距离的地方制作平行线。但是正如你在下面看到的,当线条接近南北时,它看起来相当不错,但是当你走向东方和西方时,它看起来像两条线之间的距离不是相同的值。终点似乎是正确的距离,但抵消。我怎么能这样做,所以所有的线看起来像第一个图像,不管朝哪个方向?

  public void onMarkerDragEnd(Marker marker) {
showDistance();


LatLng markerCPosition = SphericalUtil.computeOffset(mMarkerA.getPosition(),50,90);

mMarkerC = getMap()。addMarker(new MarkerOptions()。position(markerCPosition).draggable(true).visible(false));

LatLng markerDPosition = SphericalUtil.computeOffset(mMarkerB.getPosition(),50,90);

mMarkDD = getMap()。addMarker(new MarkerOptions()。position(markerDPosition).draggable(true).visible(false));

updatePolyline();
}



解决方案

目前,您只需使用恒定角度(90度)将点横向移动。如果我正确地理解了你,并且你希望两条线彼此平行并相隔一段距离,那么你需要考虑原始AB线的标题,如下所示:

  double heading = SphericalUtil.computeHeading(posA,posB); 
LatLng markerCPosition = SphericalUtil.computeOffset(posA,50,heading + 90);
LatLng markerDPosition = SphericalUtil.computeOffset(posB,50,heading + 90);


I'm using the computeOffset() from the SpericalUtil in the google maps android library. The computeOffset takes the parameters:

public static LatLng computeOffset(LatLng from, double distance, double heading)

with the original coordinates of the first two markers I can use the computeOffset to generate another line after inputing the distance and the heading. My goal is to make parallel lines at a certain distance apart. But as you can see below it looks pretty good when the lines are nearly north and south, but when you go towards east and west it looks to me like the distance between the two lines isn't the same value. The end points appear to be the right distance but offset. How can I make it so all the lines look like the first image no matter what direction?

public void onMarkerDragEnd(Marker marker) {
    showDistance();


LatLng markerCPosition = SphericalUtil.computeOffset(mMarkerA.getPosition(), 50, 90); 

    mMarkerC = getMap().addMarker(new MarkerOptions().position(markerCPosition).draggable(true).visible(false));

LatLng markerDPosition = SphericalUtil.computeOffset(mMarkerB.getPosition(), 50, 90);

    mMarkerD = getMap().addMarker(new MarkerOptions().position(markerDPosition).draggable(true).visible(false));

    updatePolyline();
}

解决方案

At the moment you're just shifting the points sideways using a constant angle (90 degrees). If I understand you correctly and you want both lines parallel to each other separated by some distance you need to take into account the heading of the original A-B line like so:

double heading = SphericalUtil.computeHeading(posA, posB);
LatLng markerCPosition = SphericalUtil.computeOffset(posA, 50, heading + 90);
LatLng markerDPosition = SphericalUtil.computeOffset(posB, 50, heading + 90);

这篇关于Google Maps SphericalUtil computeOffset的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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