在我的地图应用程序中,它没有在棉花糖上显示位置,但它完全在棉花糖下方显示位置和所有标记点。
context = MapsActivity.this;
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
mMap = googleMap;
//drawing marker
pointOne = new LatLng(23.10, 72.50847684);
mMap.addMarker(new MarkerOptions().position(pointOne).title("Point 1"));
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.ACCESS_FINE_LOCATION)) {
Toast.makeText(this,"Permission IS required",Toast.LENGTH_SHORT).show();
}
return;
}
在这里,我给了所有运行时权限,但是我无法看到我的位置。 感谢您的帮助。
答案 0 :(得分:2)
棉花糖版兄弟的许可问题。
首先,您必须打开设备的位置。
复制此代码并将您的活动类粘贴到onCreate()方法中。
ActivityCompat.requestPermissions(getActivity(), new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION, android.Manifest.permission.ACCESS_COARSE_LOCATION},
LOCATION_PERMISSION_REQUEST_CODE);
答案 1 :(得分:1)
尝试此代码并请检查是否授予运行时权限
http://javapapers.com/android/android-location-tracker-with-google-maps/