我正在使用自定义纬度和经度标记创建Google地图。这些标记在三星S4手机上显示正常,但它们不会在S8或更高版本上显示。我批准了所有的许可。我还将点击监听器放在自定义标记上。这些都可以在S4或低版本中正常工作,但在高版本的api mobile中无法正常工作。
我哪里错了?这是我的代码:
if (ActivityCompat.checkSelfPermission(getActivity(),
Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(getActivity(),
Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
requestPermission();
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode,
String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the
documentation
// for ActivityCompat#requestPermissions for more details.
// return false;
} else {
mSetUpMap();
}
private void requestPermission() {
ActivityCompat.requestPermissions(getActivity(), new
String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
}
public void mSetUpMap() {
googleMap.clear();
/**Create dummy Markers List*/
List<Marker> markersList = new ArrayList<Marker>();
for (City item : cityList) {
if (googleMap != null) {
Marker m1 = googleMap.addMarker(new MarkerOptions().position(new
LatLng(item.getLatitude(),
item.getLongitude())).title(item.getName()).anchor(0.5f,
0.5f).icon(BitmapDescriptorFactory.fromBitmap(getCustomMarker(
item.getDrawableId(), item.getName()))));
markersList.add(m1);
}
}
googleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(final Marker marker) {
ValueAnimator ani = ValueAnimator.ofFloat(0, 1); //change for
(0, 1)if you want a fade in
ani.setDuration(2000);
ani.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
marker.setAlpha((float) animation.getAnimatedValue());
}
});
ani.start();
if (marker.getTitle().equals(cityList.get(0).getName())) {
AppUtil.city = cityList.get(0);
} else if (marker.getTitle().equals(cityList.get(1).getName())) {
AppUtil.city = cityList.get(1);
} else if (marker.getTitle().equals(cityList.get(2).getName())) {
AppUtil.city = cityList.get(2);
} else if (marker.getTitle().equals(cityList.get(3).getName())) {
AppUtil.city = cityList.get(3);
} else if (marker.getTitle().equals(cityList.get(4).getName())) {
AppUtil.city = cityList.get(4);
}
FragmentTransaction transaction =
getFragmentManager().beginTransaction();
transaction.replace(R.id.frame_container, new
CityDetailFragment());
transaction.commit();
/*((CityDetailFragment) adapter.getItem(1)).setupData();
viewPager.setCurrentItem(1,false);*/
return true;
}
});
/**create for loop for get the latLngbuilder from the marker list*/
builder = new LatLngBounds.Builder();
for (Marker m : markersList) {
builder.include(m.getPosition());
}
/**initialize the padding for map boundary*/
final int padding = 150;
/**create the bounds from latlngBuilder to set into map camera*/
final LatLngBounds bounds = builder.build();
/**create the camera with bounds and padding to set into map*/
cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
/**call the map call back to know map is loaded or not*/
googleMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
@Override
public void onMapLoaded() {
googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds,
padding));
googleMap.animateCamera(CameraUpdateFactory.zoomTo(12));
}
});
}
private Bitmap createStoreMarker() {
ViewGroup continer = null;
View markerLayout = view.inflate(null,
R.layout.store_marker_layout, continer);
markerLayout.measure(View.MeasureSpec.makeMeasureSpec(0,
View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0,
View.MeasureSpec.UNSPECIFIED));
markerLayout.layout(0, 0, markerLayout.getMeasuredWidth(),
markerLayout.getMeasuredHeight());
final Bitmap bitmap =
Bitmap.createBitmap(markerLayout.getMeasuredWidth(),
markerLayout.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
markerLayout.draw(canvas);
return bitmap;
}
答案 0 :(得分:2)
试试这个
const myArray = [
{
'score': 4,
'name': 'foo'
},{
'score': 1,
'name': 'bar'
},{
'score': 3,
'name': 'foobar'
}
]
const myOrderedArray = _.sortBy(myArray, o => o.name);
console.log(myOrderedArray);