我正在获取LatLng值,并且我将所有这些latlngs放入arraylist(points),当我调试代码时,我可以看到latlng点正在进入arraylist,但我没有在地图上获得折线。先感谢您。
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 :(得分:0)
调用broadcastreceiver时不要创建arraylist。 愿这对你有所帮助。
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);
}
}
};
}