卡住了List和retrofit2以及foreach

时间:2016-09-05 12:22:02

标签: java list foreach retrofit2

我正在尝试使用Retrofit 2.1.0从1.9.0升级在响应中我无法运行我想要放在地图上的标记。 在Retrofit 1.9.0上,它工作得很完美,但想要使用更新的系统。

Retrofit adapter = new Retrofit.Builder()
                .baseUrl( AppConfig.URL_PINS )
                .addConverterFactory(GsonConverterFactory.create())
                .build();

MapPinsApiInterface pinsApiInterface = adapter.create(MapPinsApiInterface.class);
Call<List<MapPins>> pins = (Call<List<MapPins>>) pinsApiInterface.getStreams();
pins.enqueue(new Callback<List<MapPins>>() {
    @Override
    public void onResponse(Call<List<MapPins>> pins, Response<List<MapPins>> response) {
        if (!isAdded() || pins == null )
            return;

        int numMarkersInRainbow[] = {
            R.mipmap.homecenter,
            R.mipmap.shop,
            R.mipmap.marksilv,
            R.mipmap.markgold,
            R.mipmap.markgreen,
            R.mipmap.markoran,
            R.mipmap.itsyou,
            R.mipmap.no_gps
        };
        bounds = new LatLngBounds.Builder();

        for (MapPins pin : pins) {    <***** Here is my error ***>
            MarkerOptions options = new MarkerOptions().position(new LatLng(pin.getLatitude(), pin.getLongitude()));
            options.title(pin.getName());
            options.snippet(pin.getDepth());
            options.icon(BitmapDescriptorFactory.fromResource(numMarkersInRainbow[pin.getMarker()]));

            Marker mkr = googleMap.addMarker(options);
            mMarkers.put(mkr.getId(), pin.getSiteid());
            bounds.include(new LatLng(pin.getLatitude(), pin.getLongitude()));
        }
    }

在行中:(MapPins pin : pins) {

我收到错误

  

每个不适用于'retrofit2.call'的类型

我确信我忽视了一些事情。我错过了什么?

1 个答案:

答案 0 :(得分:2)

您需要使用您获得的var image = new Image(); var canvas = document.createElement('canvas'); canvas.width =1090; canvas.height = 1875; var context = canvas.getContext('2d'); context.drawSvg(xml, 0, 0); image.src = canvas.toDataURL(); 个实例,然后您可以获取retrofit2.Response List<MapPins>

for (MapPins pin : response.body()) {
    // ...
}

但您还应该检查body of the response

if (!response.isSuccessful()) {
    // handle
}