我搜索过相关问题但没有找到。我创建了一个显示图片、名称和地址的 InfoWindowMarker。然后我创建 OnInfoWindowClickListener 将显示所选标记的纬度和经度。但是当我单击信息窗口时,我收到此错误消息。
Logcat:
com.xxxxxxxx.xxxxxxxxx E/Zygote:Zygote:关闭描述符时出错
libcore.io.ErrnoException:关闭失败:EBADF(错误文件号)
在 libcore.io.Posix.close(本机方法)
在 libcore.io.BlockGuardOs.close(BlockGuardOs.java:75)
在 com.android.internal.os.ZygoteInit.closeServerSocket(ZygoteInit.java:221)
在 com.android.internal.os.ZygoteConnection.handleChildProc(ZygoteConnection.java:879)
在 com.android.internal.os.ZygoteConnection.runOnce(ZygoteConnection.java:242)
在 com.android.internal.os.ZygoteInit.runSelectLoop(ZygoteInit.java:713)
在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:649)
在dalvik.system.NativeStart.main(本机方法)
信息窗口适配器:
public GoogleMap.InfoWindowAdapter CustomMarkerInfo = new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker marker) {
ViewGroup viewGroup = (ViewGroup)getLayoutInflater().inflate(R.layout.custom_info_window, null);
ImageView ivRow = (ImageView)viewGroup.findViewById(R.id.ivRowImage);
TextView locationName = (TextView)viewGroup.findViewById(R.id.tvRowTitle);
TextView locationAddress = (TextView)viewGroup.findViewById(R.id.tvRowTitle2);
Bitmap locationImage;
locationName.setText(marker.getTitle());
locationAddress.setText(marker.getSnippet());
URL imageURL;
try {
imageURL = new URL(markerInfo.get(marker.getId()));
locationImage = BitmapFactory.decodeStream(imageURL.openConnection().getInputStream());
ivRow.setImageBitmap(locationImage);
}catch (Exception e){
e.printStackTrace();
}
return viewGroup;
}
@Override
public View getInfoContents(Marker marker) {return null;}
};
OnInfoWindowClickListener:
private GoogleMap.OnInfoWindowClickListener onInfoWindowClickListener = new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
LatLng myLatLng = myLatLng();
Toast.makeText(getApplicationContext(),myLatLng.toString(),Toast.LENGTH_LONG).show();
}
};
private final LocationListener locationListener = new LocationListener() {
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {}
@Override
public void onProviderEnabled(String provider) {}
@Override
public void onProviderDisabled(String provider) {}
@Override
public void onLocationChanged(Location newLocation) {
}
};
private LatLng myLatLng(){
LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
String provider;
Location location;
LatLng myLatLng = null;
if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
provider = LocationManager.GPS_PROVIDER;
Toast.makeText(getApplicationContext(),"GPS tidak aktif.",Toast.LENGTH_LONG).show();
}else if(locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)){
provider = LocationManager.NETWORK_PROVIDER;
}else{
provider = LocationManager.PASSIVE_PROVIDER;
}
if(locationManager.getLastKnownLocation(provider) == null){
locationManager.requestLocationUpdates(provider,2000,10,locationListener);
location = locationManager.getLastKnownLocation(provider);
if(location == null){
Toast.makeText(getApplicationContext(),"Tidak dapat menemukan lokasi saat ini, coba lagi.",Toast.LENGTH_LONG).show();
}else{
location = locationManager.getLastKnownLocation(provider);
myLatLng = new LatLng(location.getLatitude(),location.getLongitude());
}
}else{
location = locationManager.getLastKnownLocation(provider);
myLatLng = new LatLng(location.getLatitude(),location.getLongitude());
}
return myLatLng == null ? myLatLng() : myLatLng;
}
感谢任何解决方案。
更新:从加载的 JSON 创建的标记。如果是的话可能会导致这个问题。