如何画线聚在谷歌地图 - 机器人 [英] How to draw poly line in google map -- android

查看:268
本文介绍了如何画线聚在谷歌地图 - 机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的谷歌地图版本2.我用来绘制在给定的经纬度线。我可以能够利用那些行。有没有什么方法来绘制特定的时间线线。例如,我有的latLng名单,我想绘制每3秒聚线。为此,我使用了Thread.sleep(2000年)。但是,当我这样做,我的设备得到了来袭,之后所有itterate做我可以看到行指定的LatLng绘图。是否有任何其他的方式来绘制特定的时间线线。在此先感谢

 的PolylineOptions polylineOptionsPlay =新的PolylineOptions();
          的for(int i = 0; I< listPoint.size();我++){
                尝试{
                    的System.out.println(ⅰ);
                    经纬度drawpoly = listPoint.get(I)
                    Log.v(TAG,你好::+ drawpoly);
                    polylineOptionsPlay.add(drawpoly);
                    。//googleMap.addPolyline(new的PolylineOptions()加(locLatLng));
                    折线= googleMap.addPolyline(polylineOptionsPlay);
                    polyline.setColor(Color.BLUE);
                    polyline.setWidth(2);                    视频下载(2000);                } //System.out.println(stem[0]);
                赶上(InterruptedException的前){                }


解决方案

如果您实现线程或HandlerThread,请确保您的UI线程不会阻塞在等待工作线程来完成 - 不调用Thread.wait()和Thread.sleep()

http://developer.android.com/training/articles/perf- anr.html

您不应该调用Thread.sleep()方法,这将阻止用户界面线程。相反,你可以使用处理程序

Considetring listPoint 的纬度和经度的列表,你可以做如下

声明下面的类变量。

 处理程序m_handler;
可运行m_handlerTask;
INT T = 0;

使用处理程序来以3秒的延迟使用绘制折线lat和长

  m_handler =新的处理程序();
m_handlerTask =新的Runnable()
{
@覆盖
公共无效的run(){
如果(T< listPoint.size() - 1)
{
经纬度SRC = listPoint.get(T);
经纬度DEST = listPoint.get(T + 1);
折线行= mMap.addPolyline(新的PolylineOptions()
    。新增(新经纬度(src.latitude,src.longitude)
    新的经纬度(dest.latitude,dest.longitude))
    .WIDTH(2)。颜色(Color.BLUE).geodesic(真));
    Ť++;
    }
    其他
    {
   m_handler.removeCallbacks(m_handlerTask);
    }
   m_handler.postDelayed(m_handlerTask,3000);
    }
};
m_handlerTask.run();

I am new to google map version 2. I used to draw a line in given LatLng. I can able to draw those line. Is there any way to draw line for specific time line. For example, i have list of latLng, i want to draw a poly line for every 3 sec. for this i used Thread.sleep(2000). But when i am doing this, my device got struck, after the all itterate done i can see the line drawing in given latLng. Is there any other way to draw line in specific time line. Thanks in advance

    PolylineOptions polylineOptionsPlay =   new PolylineOptions();
          for (int i = 0; i < listPoint.size(); i++) {
                try {
                    System.out.println(i);
                    LatLng drawpoly = listPoint.get(i);
                    Log.v(TAG, "Hello :: "+drawpoly);
                    polylineOptionsPlay.add(drawpoly);
                    //googleMap.addPolyline(new PolylineOptions().add(locLatLng));
                    polyline = googleMap.addPolyline(polylineOptionsPlay);
                    polyline.setColor(Color.BLUE);
                    polyline.setWidth(2);

                    Thread.sleep(2000);

                } //System.out.println(stem[0]);
                catch (InterruptedException ex) {

                }

解决方案

If you implement Thread or HandlerThread, be sure that your UI thread does not block while waiting for the worker thread to complete—do not call Thread.wait() or Thread.sleep().

http://developer.android.com/training/articles/perf-anr.html

You should not call Thread.sleep() which will block the ui thread. Instead you can use a Handler.

Considetring listPoint has list of latitudes and longitudes you can do as below

Declare the below as class variables.

Handler m_handler;
Runnable m_handlerTask ;
int t=0;

Use a Handler to with a delay of 3 seconds to draw polylines using lat and long

m_handler = new Handler();
m_handlerTask = new Runnable()
{
@Override 
public void run() { 
if(t<listPoint.size()-1)
{     
LatLng src = listPoint.get(t);
LatLng dest = listPoint.get(t + 1);
Polyline line = mMap.addPolyline(new PolylineOptions()
    .add(new LatLng(src.latitude, src.longitude),
    new LatLng(dest.latitude,dest.longitude))                                       
    .width(2).color(Color.BLUE).geodesic(true)); 
    t++;
    }
    else
    {
   m_handler.removeCallbacks(m_handlerTask);
    } 
   m_handler.postDelayed(m_handlerTask, 3000);    
    }
};
m_handlerTask.run(); 

这篇关于如何画线聚在谷歌地图 - 机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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