Android GoogleMaps - 添加圈子以映射for循环 - 圈子不显示

时间:2017-05-19 16:32:57

标签: android google-maps

我正在玩一项活动。我试图将圆圈添加到一组HashMap值的地图片段中。

我似乎无法通过迭代来绘制它们。

有人知道问题是什么吗?有什么方法可以解决这个问题吗?

    @Override
protected void onCreate(Bundle savedInstanceState) {

    //set zoom level using listener and keep it for on location change
    PopUpdateThread popUpdateRunnable = new PopUpdateThread();
    Thread popUpdate = new Thread(popUpdateRunnable);
    popUpdate.start();

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.main_map);
    mapFragment.getMapAsync(this);


}



@Override
public void onMapReady(GoogleMap googleMap) {


    mMap = googleMap;


    StyledMap.styleMap(mMap, this);


    mMap.moveCamera(CameraUpdateFactory.zoomTo(14));
    //Initialize Google Play Services
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (ContextCompat.checkSelfPermission(this,
                android.Manifest.permission.ACCESS_FINE_LOCATION)
                == PackageManager.PERMISSION_GRANTED) {
            buildGoogleApiClient();
            mMap.setMyLocationEnabled(true);
        }
    } else {
        buildGoogleApiClient();
        mMap.setMyLocationEnabled(true);
    }



    mMap.moveCamera(CameraUpdateFactory.zoomTo(14));

    for (Pop pop : PopCollector.getCurrentPops().values()) {

        com.morticia.android.pop.pops.LatLng center = pop.getCircle().getCenter();
        LatLng latLng = new LatLng(center.getLatitude(), center.getLongitude());


        mMap.addCircle(new CircleOptions()
                .center(latLng)
                .strokeColor(pop.getCircle().getFillColor())
                .strokeWidth(pop.getCircle().getStrokeWidth())
                .radius(pop.getCircle().getRadius())
                .fillColor(pop.getCircle().getFillColor()));
}

当我添加单独的代码行时,例如:

mMap.addCircle(new CircleOptions.center(latLng).radius(500.00).strokeWidth(10);

工作正常。有没有人知道为什么for循环方法不起作用?

1 个答案:

答案 0 :(得分:0)

我改变了

        mMap.addCircle(new CircleOptions()
            .center(latLng)
            .strokeColor(pop.getCircle().getFillColor())
            .strokeWidth(pop.getCircle().getStrokeWidth())
            .radius(pop.getCircle().getRadius())
            .fillColor(pop.getCircle().getFillColor()));

    mMap.addCircle(new CircleOptions()
            .center(latLng)
            .strokeColor(pop.getCircle().getStrokeColor())
            .strokeWidth(pop.getCircle().getStrokeWidth())
            .radius(pop.getCircle().getRadius())
            .fillColor(pop.getCircle().getFillColor()));