OSMdroidでアイコンを表示して移動したときに現在位置の地図を見つけて更新したい.特定の場所の緯度と経度を指定してアイコンを描画する場合は問題ありませんが、現在の場所の緯度と経度を指定すると2つのエラーが発生します.
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
mResourceProxy = new DefaultResourceProxyImpl(getApplicationContext());
setContentView(R.layout.main);
mMapView = (MapView) this.findViewById(R.id.mapview);
mMapView.setTileSource(TileSourceFactory.MAPNIK);
mMapView.setBuiltInZoomControls(true);
mMapView.setMultiTouchControls(true);
mapController = this.mMapView.getController();
mapController.setZoom(15);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW);
String provider = mLocMgr.getBestProvider(criteria, true);
Location location = mLocMgr.getLastKnownLocation(provider);
GeoPoint mypoint = new GeoPoint(location.getLatitude(), location.getLongitude()); // centre map here
GeoPoint mypointicon = new GeoPoint(location.getLatitude()+1000, location.getLongitude()+1000); // icon goes here
mapController.setCenter(mypoint);
mLocMgr = (LocationManager) getSystemService(LOCATION_SERVICE);
mLocMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 100,
this);
ArrayList<OverlayItem> items=new ArrayList<OverlayItem>();
items.add(new OverlayItem("Here", "Sample Description", mypointicon));
this.mMyLocationOverlay = new ItemizedIconOverlay<OverlayItem>(items,
new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
@Override
public boolean onItemSingleTapUp(final int index,
final OverlayItem item) {
Toast.makeText(
MapOverLayGiveActivity.this,
"Item '" + item.mTitle, Toast.LENGTH_LONG).show();
return true; // We 'handled' this event.
}
@Override
public boolean onItemLongPress(final int index,
final OverlayItem item) {
Toast.makeText(
MapOverLayGiveActivity.this,
"Item '" + item.mTitle ,Toast.LENGTH_LONG).show();
return false;
}
}, mResourceProxy);
this.mMapView.getOverlays().add(this.mMyLocationOverlay);
mMapView.invalidate();
}
エラー: java.lang.NullPointerException
java.lang.RunTimeException
コードのどこが間違っていますか?どうすればそれを行うことができますか? ありがとう...