我得到LatLng点但折线没有在地图上显示

问题描述:

我得到LatLng值,并且我将所有这些latlngs放到arraylist(点)中,当我调试代码时我可以看到latlng点正在进入进入数组列表,但我没有在地图上找到折线。先谢谢你。我得到LatLng点但折线没有在地图上显示

private BroadcastReceiver receiver = new BroadcastReceiver() { 
    @Override 
    public void onReceive(Context context, Intent intent) { 
     if (intent.getExtras() != null) { 
      points=new ArrayList<LatLng>(); 
      Lat=bundle.getDouble("latitude", 0d); 
      Lng=bundle.getDouble("longitude", 0d); 
         Toast.makeText(getApplicationContext(),""+Lat+","+Lng,Toast.LENGTH_SHORT).show()‌​; 
      point = new LatLng(Lat,Lng); 
      PolylineOptions polylineOptions = new PolylineOptions(); 
      polylineOptions.color(Color.BLUE); 
      polylineOptions.width(8); 
      points.add(point); 
      polylineOptions.addAll(points); 
      googleMap.addPolyline(polylineOptions); 
     } 
    } 
}; 
+0

你会改变polylineOptions.addAll(points);用循环和尝试? for(int i = 0; i Signare 2015-04-06 06:30:37

+0

尝试此示例http://www.androidhub4you.com/2013/07/draw-polyline-in-google-map-version-2.html – Signare 2015-04-06 06:32:25

+0

我想你正在执行此代码在一个循环中,你要添加指向ArrayList,所以julst将最后两行移出你的循环,你将得到你的地图上绘制的所有多段线。最后两行'polylineOptions.addAll(points); googleMap.addPolyline(polylineOptions);' – Pankaj 2015-04-06 06:37:15

不要在调用广播接收机时重新创建数组列表。 这可以帮助你。

public class MainActivity extends Activity { 
    ArrayList<LatLng> points=new ArrayList<LatLng>(); 
private BroadcastReceiver receiver = new BroadcastReceiver() { 
@Override 
public void onReceive(Context context, Intent intent) { 
    if (intent.getExtras() != null) { 

     Lat=bundle.getDouble("latitude", 0d); 
     Lng=bundle.getDouble("longitude", 0d); 
        Toast.makeText(getApplicationContext(),""+Lat+","+Lng,Toast.LENGTH_SHORT).show()‌​; 
     point = new LatLng(Lat,Lng); 
     PolylineOptions polylineOptions = new PolylineOptions(); 
     polylineOptions.color(Color.BLUE); 
     polylineOptions.width(8); 
     points.add(point); 
     polylineOptions.addAll(points); 
     googleMap.addPolyline(polylineOptions); 
    } 
    } 
}; 
} 
+0

它的工作非常感谢你.... – 2015-04-06 09:42:13

+0

如果这解决了你的问题,PLZ接受这个答案。 – 2015-04-06 13:21:08