将URL中的图像加载到customInfoWindow Google Maps中

时间:2017-12-14 08:30:18

标签: java android google-maps

正在使用自定义信息窗口实施谷歌地图。窗口工作正常,但由于某种原因,图像没有加载到我的imageView。我也没有看到任何错误。

我正在尝试将图片从网址加载到自定义标记信息窗口中的imageView

enter image description here

我想将图片加载到顶部。图片网址看起来像这样。 https://lh3.googleusercontent.com/p/AF1QipNP6n3JeoWAWo8WhS7-RTC0e3o-R04EUx7gJeOX=s1600-w1400

爪哇

  @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;

        mMap.getUiSettings().setZoomControlsEnabled(true);


        LatLng snowqualmie = new LatLng(Double.parseDouble(Latitude), Double.parseDouble(Longitude));

        MarkerOptions markerOptions = new MarkerOptions();
        markerOptions.position(snowqualmie)
                .title(Name)
                .snippet(Description)
                .icon(BitmapDescriptorFactory.defaultMarker( BitmapDescriptorFactory.HUE_BLUE));





        mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {



            @Override
            public View getInfoWindow(Marker marker) {
                return null;
            }



            @Override
            public View getInfoContents(Marker marker) {
                View view = getLayoutInflater().inflate(R.layout.map_info_window, null);
                final ImageView infoImage = view.findViewById(R.id.info_image);
                TextView InfoName = view.findViewById(R.id.info_tv_name);
                TextView Lati = view.findViewById(R.id.Info_latitude);
                TextView Longi = view.findViewById(R.id.info_longitude);
                TextView Addres = view.findViewById(R.id.info_address);
                TextView Desc = view.findViewById(R.id.info_description);

                TextView msg_Address = findViewById(R.id.tv_msg_address);
                TextView msg_Description = findViewById(R.id.tv_msg_description);

                InfoName.setText(MapDisplay.Name);
                Lati.setText(MapDisplay.Latitude);
                Longi.setText(MapDisplay.Longitude);

                Picasso.with(context)
                        .load(Uri.parse(MapDisplay.ImageURL))
                        .fit().centerCrop()
                        .into(infoImage);

                    if (MapDisplay.Address == "" || MapDisplay.Address == null || MapDisplay.Address.length() == 0){
                        Addres.setText("No address added.");
                    }else {
                        Addres.setText(MapDisplay.Address);
                    }


                    if (MapDisplay.Description == "" || MapDisplay.Description == null || MapDisplay.Description.length() == 0){
                        Desc.setText("No description added.");
                    }else {
                        Desc.setText(MapDisplay.Description);
                    }

                return view;
            }
        });

        googleMap.setOnInfoWindowClickListener(this);


//        // Add a marker in Sydney and move the camera
        LatLng Location = new LatLng(Double.parseDouble(Latitude), Double.parseDouble(Longitude));
        mMap.addMarker(new MarkerOptions().position(Location).title(Name));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(Location));
        CameraPosition cameraPosition = new CameraPosition.Builder().target(Location).zoom(16).build();
        mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));


    }

有人可以帮我解决这个问题。 TNX

3 个答案:

答案 0 :(得分:1)

我在代码下面会遇到同样的问题:

private void setInfoWindow() {
    googleMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
        @Override
        public View getInfoWindow(Marker marker) {
            return null;
        }

        @Override
        public View getInfoContents(Marker marker) {

            View v = View.inflate(this, R.layout.custom_info_window, null);
           ImageView imageViewPic = v.findViewById(R.id.img_event);
           Picasso.with(this).load(mUrl).resize(80, 70).centerInside().into(url);
           return v;
        }
    });
}

答案 1 :(得分:1)

尝试删除毕加索的

  

.fit()。centerCrop()

控制图像视图大小,通过XML缩放属性,您在其中定义了imageView(" info_image")

答案 2 :(得分:0)

您应该使用此代码帮助我,

添加此依赖项:

compile 'com.github.bumptech.glide:glide:3.8.0'

并在infowindow点击时添加:

 Glide.with(getActivity())
                            .load(Uri.parse(MapDisplay.ImageURL)).placeholder(R.drawable.img_profile_dumy)
                            .listener(new RequestListener<String, GlideDrawable>() {
                                @Override
                                public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
                                    return false;
                                }

                                @Override
                                public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                                    if (marker.isInfoWindowShown()) {
                                        marker.hideInfoWindow();
                                        marker.showInfoWindow();
                                    }
                                    return false;
                                }
                            }).into(img_profile);

使用此第一次滑行不显示图像,但此处回调重新成功时再显示信息窗口。 这对你有帮助。