Java 将URL中的图像加载到customInfoWindow谷歌地图
我正在用自定义信息窗口实现谷歌地图。窗口工作正常,但由于某些原因,图像未加载到我的Java 将URL中的图像加载到customInfoWindow谷歌地图,java,android,google-maps,Java,Android,Google Maps,我正在用自定义信息窗口实现谷歌地图。窗口工作正常,但由于某些原因,图像未加载到我的imageView。我也没有看到任何错误 我正在尝试将图像从URL加载到自定义标记信息窗口内的imageView 我想将图像加载到顶部。图像url如下所示。 https://lh3.googleusercontent.com/p/AF1QipNP6n3JeoWAWo8WhS7-RTC0e3o-R04EUx7gJeOX=s1600-w1400 Java @Override public void onM
imageView
。我也没有看到任何错误
我正在尝试将图像从URL加载到自定义标记信息窗口内的imageView
我想将图像加载到顶部。图像url如下所示。
https://lh3.googleusercontent.com/p/AF1QipNP6n3JeoWAWo8WhS7-RTC0e3o-R04EUx7gJeOX=s1600-w1400
Java
@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你应该把这段代码告诉我 添加此依赖项:
compile 'com.github.bumptech.glide:glide:3.8.0'
并在信息窗口单击时将其添加到:
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);
Glide.with(getActivity())
.load(Uri.parse(MapDisplay.ImageURL)).placeholder(R.drawable.img_profile_dumy)
.listener(新的RequestListener(){
@凌驾
公共布尔onException(异常e、字符串模型、目标、布尔isFirstResource){
返回false;
}
@凌驾
公共布尔值onResourceReady(GlideDrawable资源、字符串模型、目标、布尔值isFromMemoryCache、布尔值isFirstResource){
if(marker.isinfownshown()){
marker.hideInfo窗口();
marker.showInfoWindow();
}
返回false;
}
}).进入(img_档案);
使用此第一次滑动不显示图像,但在这里当回调重新返回成功,然后再次显示信息窗口。
这将对您有所帮助。我有同样的问题,我将使用以下代码:
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;
}
});
}
试着把毕加索的画去掉 .fit().centerCrop()中的
控制图像视图大小,通过XML缩放属性,在XML中定义图像视图(“信息图像”)您可以检查获取URL是否正确,并记录它并检查URL是否进入web浏览器Yes URL工作正常。我已在问题中添加了url链接。请尝试使用Glide加载图像以检查我的答案链接:请查看此链接