gpt4 book ai didi

android - Google map 中的自定义标记未在三星 S8 或相同版本 7.0 中显示

转载 作者:太空宇宙 更新时间:2023-11-03 13:42:22 26 4
gpt4 key购买 nike

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

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

}
}

关于android - Google map 中的自定义标记未在三星 S8 或相同版本 7.0 中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49315032/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com