我已经尝试了几天,我开始拉头发了。 Android和Osmdroid的Noob。
我可以构建并且已经成功完成了osmdroid演示应用程序。还尝试了OSMbonuspack并让导航器与"找到我"叠加,缩放等。
问题是每当我制作自己的应用程序时,唯一显示并在我的地图中工作的叠加层就是指南针。我想我做错了什么但找不到关于这个主题的任何信息。
我用Genymotion虚拟设备测试了这个(甚至没有指南针显示)和我的6.0移动指南针工作,但没有MyLocation甚至Scale。
我已经给出了应用程序权限,我在android日志中看到的所有内容都是关于在移动地图时加载tile的消息。再加上这个错误,除了中文外,我还没有找到很多信息。
E / IzatSvc_PassiveLocListener:E / Exiting with error virtual void izat_manager :: IzatPassiveLocationListener :: onLocationChanged(const izat_manager :: IzatLocation *,izat_manager :: IzatLocationStatus)第113行" 1"
欢迎任何帮助!
这是我的manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.anemptyappmap">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
这是MainActivity.java
package com.example.anemptyappmap;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import org.osmdroid.api.IMapController;
import org.osmdroid.tileprovider.constants.OpenStreetMapTileProviderConstants;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.ScaleBarOverlay;
import org.osmdroid.views.overlay.compass.CompassOverlay;
import org.osmdroid.views.overlay.compass.InternalCompassOrientationProvider;
import org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider;
import org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay;
public class MainActivity extends AppCompatActivity {
//Vars para mapa
private MyLocationNewOverlay mLocationOverlay;
private CompassOverlay mCompassOverlay=null;
//private MinimapOverlay mMinimapOverlay;
private ScaleBarOverlay mScaleBarOverlay;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Context context = getApplicationContext();
final DisplayMetrics dm = context.getResources().getDisplayMetrics();
OpenStreetMapTileProviderConstants.setUserAgentValue(BuildConfig.APPLICATION_ID);
String cachePath = getCacheDir().getAbsolutePath();
org.osmdroid.tileprovider.constants.OpenStreetMapTileProviderConstants.setCachePath(cachePath);
//important! set your user agent to prevent getting banned from the osm servers
//Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx));
MapView mMapView = (MapView) findViewById(R.id.mMapView);
mMapView.setTileSource(TileSourceFactory.MAPNIK);
//map.setBuiltInZoomControls(true);
mMapView.setMultiTouchControls(true);
mLocationOverlay = new MyLocationNewOverlay(new GpsMyLocationProvider(context),mMapView);
mLocationOverlay.enableMyLocation();
mLocationOverlay.setDrawAccuracyEnabled(true);
//mLocationOverlay.setPersonIcon();
mLocationOverlay.enableMyLocation();
mMapView.getOverlays().add(this.mLocationOverlay);
mCompassOverlay = new CompassOverlay(context, new InternalCompassOrientationProvider(context), mMapView);
mCompassOverlay.enableCompass();
mMapView.getOverlays().add(this.mCompassOverlay);
mScaleBarOverlay = new ScaleBarOverlay(mMapView);
mScaleBarOverlay.setScaleBarOffset(dm.widthPixels / 2, 10);
mScaleBarOverlay.setCentred(true);
mMapView.getOverlays().add(this.mScaleBarOverlay);
//this.mScaleBarOverlay.setAlignBottom(true);
//this.mScaleBarOverlay.setCentred(true);
this.mScaleBarOverlay.enableScaleBar();
//this.mMinimapOverlay = new MinimapOverlay();
IMapController mapController = mMapView.getController();
mapController.setZoom(13);
GeoPoint startPoint = new GeoPoint(43.3600, -8.2800);
mapController.setCenter(startPoint);
// mMapView.invalidate();
}
}
布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.anemptyappmap.MainActivity">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/crossfade_content"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<org.osmdroid.views.MapView android:id="@+id/mMapView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>