单击标记时会出现Google Map标题,但会立即消失

时间:2017-06-27 08:32:19

标签: android google-maps

我已经在我的Android应用程序中实现了Google地图,我希望当应用程序启动当前位置时可以使用标记显示,当点击标记时,应显示标题。但是发生了什么,标题出现并立即显示得到消失。我使用了showInfoWindow()但它显示标题,即使我在地图上滚动,我也不想要。我也尝试过hideInfoWindow(),标记点击监听器和信息窗口点击监听器,但不能找到任何解决方案。当我调试代码时,调试器转到标记点击监听器,显示标记并立即进入onCameraIdle(),标记设置的最后条件。下面是我的onMapReady(),onCameraIdle()的代码。请帮助我,找出解决方案。

MapFragment.java:-

 @Override
public void onMapReady(GoogleMap googleMap) {
if (Constants.isNetworkAvailable(MapsFragmentActivity.this)) {
mMap = googleMap;
mMap.setOnCameraMoveListener(this);
mMap.setOnMyLocationButtonClickListener(this);
mMap.setOnCameraIdleListener(this);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
return;
}
mMap.setMyLocationEnabled(true);
handleIntent(getIntent());
}
}
@Override
public void onCameraIdle() {
if (Constants.isNetworkAvailable(MapsFragmentActivity.this)) {
if (marker != null) {
marker.remove();
}
if (CameraLat == 0.0 && CameraLong == 0.0) {
CameraLat = mMap.getCameraPosition().target.latitude;
CameraLong = mMap.getCameraPosition().target.longitude;
}
Location location = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
Log.i("LOcation", "location--->" + location);

LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
Log.i("LOcation", "latLng--->" + latLng);
if (location.getLatitude() != 0.0 && location.getLongitude() != 0.0 ) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
return;
}
try {
if(!filterAddress.isEmpty()){
filterAddress="";
}
// if(location!=null) {
List<Address> addresses = geoCoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
for (int i = 0; i < addresses.get(0)
.getMaxAddressLineIndex(); i++) {
if (addresses.get(0).getAddressLine(i) != null) {
filterAddress += addresses.get(0).getAddressLine(i)
+ " ";
}
}
markerOptions.position(latLng);
markerOptions.title(filterAddress);
marker = mMap.addMarker(markerOptions);
mMap.setOnMarkerClickListener(this);

Log.i("LOcation", "filterAddress--->" + filterAddress);

} catch (IOException e) {
e.printStackTrace();
}

}
}else{
Constants.alert("No internet connection",MapsFragmentActivity.this);
}
}

0 个答案:

没有答案