谷歌地图中的自定义标记未在三星 S8 或相同版本 7.0 中显示

Custom Marker In Google Maps not Showing in Samsung S8 or same version 7.0(谷歌地图中的自定义标记未在三星 S8 或相同版本 7.0 中显示)

本文介绍了谷歌地图中的自定义标记未在三星 S8 或相同版本 7.0 中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名新的 Android 开发人员.我正在使用 lat long 地图创建谷歌地图和自定义标记,标记在 S4 移动设备中正常工作并显示,但在 s8 或更高版本的移动设备中未显示我授予所有权限.我还将点击监听器放在自定义标记上.这些都可以在 s4 或低版本的移动设备中正常工作,但不能在高版本的 api 移动设备中工作.在此先感谢..
我哪里错了?请帮我这是我的代码

I am a new Android Developer. I am creating google map and custom marker with lat long map and markers work and show proper in S4 mobile but not shown in s8 or higher version mobile I grant all permission for that.I also put click listener on Custom Marker. These all work fine in s4 or low version mobile but not work in high version api mobile. Thanks in Advance..
where i am wrong ? please help me Here is my code

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*/
   enter code here


     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;
}

推荐答案

试试这个

public class MainActivity extends AppCompatActivity implements 
OnMapReadyCallback {

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

try {

    boolean success = 

googleMap.setMapStyle(MapStyleOptions.loadRawResourceStyle(
MainActivity.this, 
R.raw.style_json));

    if (!success) {
        Log.e("google map", "Style parsing failed.");
    }
} catch (Resources.NotFoundException e) {
    Log.e("google map", "Can't find style. Error: ", e);
}

mSetUpMap();

}



private static final String TAG = "MapActivity";

private static final String FINE_LOCATION = 
Manifest.permission.ACCESS_FINE_LOCATION;
private static final String COURSE_LOCATION = 
Manifest.permission.ACCESS_COARSE_LOCATION;

private static final int LOCATION_PERMISSION_REQUEST_CODE = 1234;


 private Boolean mLocationPermissionsGranted = false;
 private GoogleMap mMap;

 @Override
 protected void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  getLocationPermission();
 }

 private void initMap(){
 Log.d(TAG, "initMap: initializing map");
 SupportMapFragment mapFragment = (SupportMapFragment) 
 getSupportFragmentManager().findFragmentById(R.id.map);

 mapFragment.getMapAsync(MainActivity.this);
 }

  private void getLocationPermission(){
  Log.d(TAG, "getLocationPermission: getting location permissions");
  String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION,
        Manifest.permission.ACCESS_COARSE_LOCATION};

  if(ContextCompat.checkSelfPermission(this.getApplicationContext(),
        FINE_LOCATION) == PackageManager.PERMISSION_GRANTED){
    if(ContextCompat.checkSelfPermission(this.getApplicationContext(),
            COURSE_LOCATION) == PackageManager.PERMISSION_GRANTED){
        mLocationPermissionsGranted = true;
        initMap();
    }else{
        ActivityCompat.requestPermissions(this,
                permissions,
                LOCATION_PERMISSION_REQUEST_CODE);
    }
   }else{
    ActivityCompat.requestPermissions(this,
            permissions,
            LOCATION_PERMISSION_REQUEST_CODE);
   }
 }

 @Override
 public void onRequestPermissionsResult(int requestCode, @NonNull 
 String[] permissions, @NonNull int[] grantResults) {
 Log.d(TAG, "onRequestPermissionsResult: called.");
 mLocationPermissionsGranted = false;




     switch (requestCode) {

        case LOCATION_PERMISSION_REQUEST_CODE : {
            // If request is cancelled, the result arrays are empty.
            if (grantResults.length > 0
                    && grantResults[0] == 
    PackageManager.PERMISSION_GRANTED) {

                // permission was granted, yay! Do the
                // contacts-related task you need to do.
                Toast.makeText(getApplicationContext(), "Permission 
 granted", Toast.LENGTH_SHORT).show();
                initMap();

            } else {

                // permission denied, boo! Disable the
                // functionality that depends on this permission.
                Toast.makeText(getApplicationContext(), "Permission 
   denied", Toast.LENGTH_SHORT).show();
            }
            return;
        }

    }


    }
private void mSetUpMap() {
 // your method code 

 }
}

这篇关于谷歌地图中的自定义标记未在三星 S8 或相同版本 7.0 中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:谷歌地图中的自定义标记未在三星 S8 或相同版本 7.0 中显示

基础教程推荐