- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我使用 Osmdroid 4.2 创建了一个 Android 应用程序。一切正常,但在过去的两周里,我在装有 Android 6.0 的 Nexus 设备上发现了问题:OSM map 未加载,你只能在 map 上看到灰色背景。 map block 在 Android 6.0 上不显示。
最佳答案
osmdroid 示例应用最近更新为支持 android m。基本上,您必须向用户询问网络和存储访问的明确权限。
这将引导您了解基础知识 http://developer.android.com/training/permissions/requesting.html
这是相关的 OSMdroid 票证 https://github.com/osmdroid/osmdroid/issues/178
这是要复制并粘贴到您的启动 Activity 中的相关代码。注意,需要 23 个构建工具
导入java.util.ArrayList;
import android.Manifest;
import android.app.ListActivity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import org.osmdroid.MapActivity;
public class SampleLoader extends ListActivity {
// ===========================================================
// Constants
// ===========================================================
// ===========================================================
// Fields
// ===========================================================
final int INTERNET=1;
final int NETSTATE=2;
final int LOCATION=3;
final int LOCATIONC=4;
final int WIFI=5;
final int STORAGE=6;
// ===========================================================
// Constructors
// ===========================================================
/** Called when the activity is first created. */
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Assume thisActivity is the current activity
int permissionCheck = ContextCompat.checkSelfPermission(this,
Manifest.permission.INTERNET);
if (permissionCheck != PackageManager.PERMISSION_GRANTED){
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.INTERNET)) {
// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
Toast.makeText(this, "Need internet access to get map tiles if working with online sources", Toast.LENGTH_LONG).show();
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.INTERNET},
INTERNET);
}
}
permissionCheck = ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_NETWORK_STATE);
if (permissionCheck != PackageManager.PERMISSION_GRANTED){
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.ACCESS_NETWORK_STATE)) {
// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
Toast.makeText(this, "Need to check network state", Toast.LENGTH_LONG).show();
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.ACCESS_NETWORK_STATE},
NETSTATE);
}
}
permissionCheck = ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION);
if (permissionCheck != PackageManager.PERMISSION_GRANTED){
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.ACCESS_FINE_LOCATION)) {
// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
Toast.makeText(this, "Need your location to place an icon on the map", Toast.LENGTH_LONG).show();
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
LOCATION);
}
}
permissionCheck = ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION);
if (permissionCheck != PackageManager.PERMISSION_GRANTED){
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.ACCESS_COARSE_LOCATION)) {
// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
Toast.makeText(this, "Need your location to place an icon on the map", Toast.LENGTH_LONG).show();
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},
LOCATIONC);
}
}
permissionCheck = ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_WIFI_STATE);
if (permissionCheck != PackageManager.PERMISSION_GRANTED){
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.ACCESS_WIFI_STATE)) {
// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
Toast.makeText(this, "Access WIFI state", Toast.LENGTH_LONG).show();
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.ACCESS_WIFI_STATE},
WIFI);
}
}
permissionCheck = ContextCompat.checkSelfPermission(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (permissionCheck != PackageManager.PERMISSION_GRANTED){
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
Toast.makeText(this, "We store tiles to your devices storage to reduce data usage and for reading offline tile stores", Toast.LENGTH_LONG).show();
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
STORAGE);
}
}
}
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case INTERNET:{
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted, yay!
} else {
// permission denied, boo! Disable the
// functionality that depends on this permission.
Toast.makeText(this,"Online map sources will be unavailable", Toast.LENGTH_LONG).show();
}
return;
}
case NETSTATE: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted, yay!
} else {
// permission denied, boo! Disable the
// functionality that depends on this permission.
Toast.makeText(this,"Online map sources will be unavailable", Toast.LENGTH_LONG).show();
}
return;
}
case LOCATION:{
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted, yay!
} else {
// permission denied, boo! Disable the
// functionality that depends on this permission.
Toast.makeText(this,"My location will be unavailable via GPS", Toast.LENGTH_LONG).show();
}
return;
}
case LOCATIONC:
{
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted, yay!
} else {
// permission denied, boo! Disable the
// functionality that depends on this permission.
Toast.makeText(this,"My location will be unavailable via Network providers", Toast.LENGTH_LONG).show();
}
return;
}
case STORAGE:{
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted, yay!
} else {
// permission denied, boo! Disable the
// functionality that depends on this permission.
Toast.makeText(this,"Offline map data and caching will be unavailable", Toast.LENGTH_LONG).show();
}
return;
}
case WIFI:{
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted, yay!
} else {
// permission denied, boo! Disable the
// functionality that depends on this permission.
Toast.makeText(this,"Data usage may not be optimized.", Toast.LENGTH_LONG).show();
}
return;
}
// other 'case' lines to check for other
// permissions this app might request
}
}
}
关于android - Osmdroid 在 Android 6.0 上运行不佳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33580183/
我正在尝试在 android.support.v4.app.Fragment 中使用 OSMdroid 的离线模式。我的图 block 是由 MOBAC 使用“OSMdroid Zip”格式在地球坐标
我一直在尝试从 osmdroid 上的地理服务器获取 WMS 瓷砖。但到目前为止还没有成功。我只是设法获得一个位于其他位置的小型版 block 地理服务器。是的,投影是正确的,因为我也在我的 Web
我有一个使用 osmdroid-android-4.1 的现有 android 应用程序。 现在我想使用新的 osmdroid-android-4.2。因此,我已将 JAR 文件(osm-androi
我尝试在我的一个应用程序中使用 OSMdroid,但我得到了这个: 运行在硬件设备Android 4.0.3 (CM9) 从 logcat 记录: 06-25 16:56:07.389: E/Andr
我的应用程序有问题,其中包括 osmdroid。每次我尝试在我的设备上运行该应用程序并触摸 map 时,该应用程序都会崩溃,并且出现此错误: 2018-10-02 14:11:45.191 1
////OSMdroid 以标记为中心//// 我添加了标记,我需要以所有标记都可见的方式映射最大的增加或减少 我的代码: public class mapcode extends Activity
我试图放置用户代理(参见 https://github.com/osmdroid/osmdroid/wiki/Important-notes-on-using-osmdroid-in-your-app
大家下午好,如何为我从文件中读取的每个点在 map 上创建或插入新的叠加层?为了阅读这些要点,我创建了一个实现FolderOverlay 的类。下面是我的项目的代码:. GeoOverlay.java
我正在使用 Android Studio 用 Java 编写一个应用程序。我已经使用 osmdroid 显示了 map ,添加了一些叠加层以在特殊位置显示标记,并向标记添加了标题和描述。 现在,我
我正在使用 Osmdroid 库来显示离线 map ,并使用折线在 map 上绘制线条。但结果线不是连续的。如果街道是弯曲的,那么这条线就断了。 我的代码: Polyline polyline
我正在使用 osmdroid,并且已将 MyLocationNewOverlay 添加到我的 map 中以显示我当前的位置。这看起来不错。我想要的是一个按钮,可以将 map 置于我当前位置的中心,类似
所以我想制作一个 CheckBoxPreference 来打开 osmdroid 中的夜间模式。但是代码没有任何作用。我在没有 PreferenceScreen 的情况下做了同样的事情,一个带有开关的
我需要有关 osmdroid 功能的代码的帮助,当我点击标记时,它不会返回标题和描述 谁能帮我...这是我的 代码 import java.util.ArrayList; import org.osm
我必须使用 osmdriod map api 实现导航。该 Activity 使用以下接收器从位置服务接收广播: public class ReceiveMessages extends Broadc
我正在尝试为 osmdroid 构建自定义缩放控件。我创建按钮并使用放大方法,如图所示 here但是当我点击按钮时没有任何反应。这是我的代码: private MapView map; @Overri
我在我的应用程序中使用 osmdroid 3.0.5 jar 来显示 map View 。我正在叠加一个由水平线和垂直线组成的叠加层。我注意到只有在某些位置,在高缩放级别时,一些线条会消失,然后在拖动
我有一个使用 OSMDroid 的项目。有一个绘制标记的循环,结束之后我必须将 map 居中放置在某个标记处。我的代码: //I have on open Cursor c Marker switch
我正在使用 OSMDroid,我有一组地理点,然后我创建了一条折线,如下所示: private void drawPolyline(ArrayList polyline) { Polyline
我正在使用 osmdroid 库来渲染 map 。我有两个间歇性变化的地理点,并希望 org.osmdroid.views.MapView 调整大小和转换以确保两个点始终可见。我可以轻松地将 map
1) 我可以使用不同的自定义标记吗? 我需要一个用于用户的位置,一个用于所有其他项目。 编辑:是的,你可以。 2) 我可以在标记中添加图像吗? 我需要为每个标记分配一个不同的图像(我将从数据库中获得)
我是一名优秀的程序员,十分优秀!