在 Google Maps Android API v2 中使用 Canvas 制作的 GroundOverlay [英] GroundOverlay made with a Canvas in Google Maps Android API v2

查看:29
本文介绍了在 Google Maps Android API v2 中使用 Canvas 制作的 GroundOverlay的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我也在尝试绘制弧线(我参考了 thisthis 问题).我将从以下网络服务中获得:

I'm also try to draw arc (I'm referencing on this and this questions). I'll get from web service following:

  • 经纬度
  • 半径(以米为单位)
  • 起始角(终止角为 startA + 60 度)

现在我遇到以下问题,因为我没有两个 LatLng,只有一个,并且在新地图 api v2 中没有用于提供给 RectF.set(point.x - radius,...)

Now I encounter on following problem because I do not have two LatLng, just one, and in new map api v2 there is no radius = Projection.metersToEquatorPixels method for providing to RectF.set(point.x - radius,...)

你有代码示例、链接等吗?

Do you have code example, links, etc?

App 的性能怎么样,因为我在地图上最多会有 500 个弧线?

Also what about performances of App, because I'll have up to 500 arcs on map?

推荐答案

从一个 LatLng 点开始,您可以计算给定距离(半径)和给定角度内的另一个 LatLng 点,如下所示:

Starting from a LatLng point you can calculate another LatLng point in a given distance (radius) and a given angle as follows:

private static final double EARTHRADIUS = 6366198;

/**
 * Move a LatLng-Point into a given distance and a given angle (0-360,
 * 0=North).
 */
public static LatLng moveByDistance(LatLng startGp, double distance,
        double angle) {
    /*
     * Calculate the part going to north and the part going to east.
     */
    double arc = Math.toRadians(angle);
    double toNorth = distance * Math.cos(arc);
    double toEast = distance * Math.sin(arc);
    double lonDiff = meterToLongitude(toEast, startGp.latitude);
    double latDiff = meterToLatitude(toNorth);
    return new LatLng(startGp.latitude + latDiff, startGp.longitude
            + lonDiff);
}

private static double meterToLongitude(double meterToEast, double latitude) {
    double latArc = Math.toRadians(latitude);
    double radius = Math.cos(latArc) * EARTHRADIUS;
    double rad = meterToEast / radius;
    double degrees = Math.toDegrees(rad);
    return degrees;
}

private static double meterToLatitude(double meterToNorth) {
    double rad = meterToNorth / EARTHRADIUS;
    double degrees = Math.toDegrees(rad);
    return degrees;
}

这篇关于在 Google Maps Android API v2 中使用 Canvas 制作的 GroundOverlay的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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