Android 折线地图 api

发布于 2024-11-01 08:44:24 字数 301 浏览 5 评论 0原文

好吧,我是android的初学者,我需要更具体地使用设备上的地图(折线)我需要做这样的事情。 Javascript Api 地图应用程序

这是一个网络应用程序,我用来追踪我所在城市的巴士路线和巴士站,我已被要求在 Android 中做同样的事情!我一直在检查android的地图api,没有在JS api中找到任何类似于折线的东西,有没有办法实现这一点?

我添加简单的叠加层没有问题我一直在检查android开发者网站中的基本教程,但我不知道如何绘制折线。

well, im a begginer in android and i need to use maps on the device more specifically (polylines) i need to do something like this.
Javascript Api maps app

this is a web app i did to track down bus routes and bus-stops on my city , and i've been asked to do the same thing in android! ive been checking the maps api for android and did not found anything similar to polyline in JS api , is there a way to achieve this?

i have no problem adding simple overlays i've been checking the basic tutorials in android developer site, but i dont know how to draw the polyline.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

日记撕了你也走了 2024-11-08 08:44:24

Android Google Maps API 中没有这样的 API。您只能先列出要绘制的路线的实际 GeoPoints,然后在 Overlay 对象上绘制点和线。没有简单的方法可以做到这一点。

There no such API in Android Google Maps API. You can only first list the actual GeoPoints of the route that you want to draw and then draw the points and lines on a Overlay object. There's just no easy way to do that.

在风中等你 2024-11-08 08:44:24

一种更简单的方法是获取点并扩展将显示图像的 ImageView 来绘制点,而不是只需要传递要绘制的点。

在我的项目中,我这样做了:

public class ImageDraw extends ImageView{
private Paint   mPaint = new Paint();
List<Point> pts = new ArrayList<Point>() ;

public ImageDraw(Context context) {
    super(context);

}
//used to send the location of the points to draw on the screen
//must be called before every redraw to update the points on the screen
public void SetPointsToDraw(List<Point> pts)
{
    this.pts = pts;
}


public ImageDraw(Context context, AttributeSet attrs)
{
    super(context,attrs);
}
public ImageDraw(Context context, AttributeSet attrs, int defStyle)
{
    super(context, attrs, defStyle);
}

@Override
public void onDraw(Canvas canvas)
{
    super.onDraw(canvas);

    Paint paintColor = mPaint;
    paintColor.setColor(Color.YELLOW);
    paintColor.setStrokeWidth(3);


    if(pts.size() > 0)
    {
        canvas.drawCircle(pts.get(0).x, pts.get(0).y, 7, paintColor);   
    }
    if (pts.size() > 1)
    {
        for (int i = 1 ; i < pts.size(); i++) {
            paintColor.setColor(Color.YELLOW);
            canvas.drawCircle(pts.get(i).x, pts.get(i).y, 7, paintColor);
            paintColor.setColor(Color.RED);
            canvas.drawLine(pts.get(i-1).x, pts.get(i-1).y, pts.get(i).x, pts.get(i).y, paintColor);
        }
    }


}

}

当您扩展 Imageview 并使用 xml 创建布局时,不要忘记将新小部件的整个包放入其中,例如:
com.Myapp.MyImageView

A more easy way to do that is get your points and extend the ImageView that will display your image to draw the points, than you just need to pass the points that you want to draw .

In my project I did this:

public class ImageDraw extends ImageView{
private Paint   mPaint = new Paint();
List<Point> pts = new ArrayList<Point>() ;

public ImageDraw(Context context) {
    super(context);

}
//used to send the location of the points to draw on the screen
//must be called before every redraw to update the points on the screen
public void SetPointsToDraw(List<Point> pts)
{
    this.pts = pts;
}


public ImageDraw(Context context, AttributeSet attrs)
{
    super(context,attrs);
}
public ImageDraw(Context context, AttributeSet attrs, int defStyle)
{
    super(context, attrs, defStyle);
}

@Override
public void onDraw(Canvas canvas)
{
    super.onDraw(canvas);

    Paint paintColor = mPaint;
    paintColor.setColor(Color.YELLOW);
    paintColor.setStrokeWidth(3);


    if(pts.size() > 0)
    {
        canvas.drawCircle(pts.get(0).x, pts.get(0).y, 7, paintColor);   
    }
    if (pts.size() > 1)
    {
        for (int i = 1 ; i < pts.size(); i++) {
            paintColor.setColor(Color.YELLOW);
            canvas.drawCircle(pts.get(i).x, pts.get(i).y, 7, paintColor);
            paintColor.setColor(Color.RED);
            canvas.drawLine(pts.get(i-1).x, pts.get(i-1).y, pts.get(i).x, pts.get(i).y, paintColor);
        }
    }


}

}

When you extends the Imageview and create the layout with xml don`t forget to put the entire package of you new widget like:
com.Myapp.MyImageView

酒几许 2024-11-08 08:44:24

FvZ的答案有效,但不是原生方式,地图上有折线,一个简单的例子
https://stackoverflow.com/a/21877742/618419

另外看看Android文档,他们有很多简单的以及精心整理的示例:
http://developer.android.com/参考/com/google/android/gms/maps/model/Polyline.html

FvZ's answer works but is not the native way, there are polylines on the map, a simple example
https://stackoverflow.com/a/21877742/618419

Also take a look at the Android Documentation, they have many simple and well put-together examples:
http://developer.android.com/reference/com/google/android/gms/maps/model/Polyline.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文