Polyline不可见Android Maps Api v2 [英] Polyline not visible Android Maps Api v2

查看:63
本文介绍了Polyline不可见Android Maps Api v2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点困惑,因为代码看起来一切都好。
问题是折线不会显示在地图上。



以下是我在每次接收到位置时调用折线的函数



(我以类似的方式添加了标记,并且它们工作得很好)

  private void addPolylineLocationOnMap(LatLng newLoc)
{
PolylineOptions poly = new PolylineOptions()
.add(newLoc)
.color(Color.BLUE)
.width (5)
。visible(true)
.zIndex(30);

googleMap.addPolyline(poly);


解决方案 > Polyline 需要多个点!

例如,传递 ArrayList< LatLng> 添加到您的方法中,并使用 addAll(),而不仅仅是 add()



$ p $ PolylineOptions 文档: LatLng ... points):将顶点添加到正在构建的多段线的末端。

或者,您可以保留对 Polyline 并使用 add()在您收到它时添加点。



将poly添加为实例变量在你的课堂上:

  PolylineOptions poly; 

然后在 onCreate()你设置了地图):

pre $ code poly = new PolylineOptions()
.color(Color.BLUE)
.width(5)
.visible(true)
.zIndex(30);

googleMap.addPolyline(poly);

然后当您收到更多积分时:

  poly.add(newLoc); 


I am a little bit confused since everything seems to be alright with the code. The problem is that the polyline won't show up on the map.

Here is the function that I call to place polyline everytime I receive a location

(I added markers in a similar way and they work great)

private void addPolylineLocationOnMap(LatLng newLoc)
{
    PolylineOptions poly = new PolylineOptions()
                                    .add(newLoc)
                                    .color(Color.BLUE)
                                    .width(5)
                                    .visible(true)
                                    .zIndex(30);

    googleMap.addPolyline(poly);
}

解决方案

A Polyline needs multiple points!

For example, pass an ArrayList<LatLng> to your method and use addAll() rather than just add().

From the PolylineOptions documentation:

add(LatLng... points) : Adds vertices to the end of the polyline being built.

Alternatively, you can keep a reference to one Polyline and use add() to add points to it as you receive them.

Add poly as an instance variable in your class:

PolylineOptions poly;

Then in onCreate() (or wherever you set up the map):

poly = new PolylineOptions()
    .color(Color.BLUE)
    .width(5)
    .visible(true)
    .zIndex(30);

googleMap.addPolyline(poly);

Then as you receive more points:

poly.add(newLoc);

这篇关于Polyline不可见Android Maps Api v2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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