0

Androidマップに緯度と経度が表示されています。しかし、現在地のマーク/ポイントを作成しようとすると、結果が表示されずにアプリがクラッシュします。これが私のコードです:

    public void onLocationChanged(Location loc)

{
    GeoPoint point = new GeoPoint(
              (int) (loc.getLatitude() * 1E6), 
              (int) (loc.getLongitude() * 1E6));

      String Text = "Latitude = " + loc.getLatitude() + "Longitude = " + loc.getLongitude();
      Toast.makeText( getApplicationContext(),Text,Toast.LENGTH_SHORT).show();

      mapcontroller.animateTo(point);
      mapcontroller.setZoom(16);

      MapOverlay mapOverlay = new MapOverlay();
      mapOverlay.setPointToDraw(point);
      List<Overlay> listOfOverlays = mapView.getOverlays();
      listOfOverlays.clear();
      listOfOverlays.add(mapOverlay);
}

     class MapOverlay extends Overlay
{
  private GeoPoint pointToDraw;

  public void setPointToDraw(GeoPoint point) {
    pointToDraw = point;
  }

  public GeoPoint getPointToDraw() {
    return pointToDraw;
  }

  public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
        super.draw(canvas, mapView, shadow);           

        // convert point to pixels
        Point screenPts = new Point();
        mapView.getProjection().toPixels(pointToDraw, screenPts);

        // add marker
        Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
        canvas.drawBitmap(bmp, screenPts.x, screenPts.y - 24, null);    
        return true;
      }
}

私のLogcatは:

    01-09 19:07:19.209: W/dalvikvm(293): threadid=1: spin on suspend resolved in 1043 msec
    01-09 19:07:19.209: D/dalvikvm(293): Restored policy of 310 to 0
    01-09 19:07:19.209: D/dalvikvm(293): Restored priority on 310 to 19
    01-09 19:07:20.220: W/dalvikvm(293): threadid=1: spin on suspend #1 threadid=7 (pcf=0)
    01-09 19:07:20.220: D/dalvikvm(293): Temporarily moving tid 309 to fg (was 0)
    01-09 19:07:20.220: D/dalvikvm(293): Temporarily raised priority on tid 309 (19 -> 0)
    01-09 19:07:20.259: W/dalvikvm(293): threadid=1: spin on suspend resolved in 1043 msec
    01-09 19:07:20.259: D/dalvikvm(293): Restored policy of 309 to 0
    01-09 19:07:20.259: D/dalvikvm(293): Restored priority on 309 to 19
    01-09 19:07:20.530: D/dalvikvm(293): GC_FOR_MALLOC freed 4877 objects / 301616 bytes in 2364ms
    01-09 19:07:21.530: D/dalvikvm(293): GC_FOR_MALLOC freed 10081 objects / 613024 bytes in 329ms
    01-09 19:07:22.460: D/dalvikvm(293): GC_FOR_MALLOC freed 4747 objects / 311336 bytes in 248ms
    01-09 19:07:23.309: D/dalvikvm(293): GC_FOR_MALLOC freed 6145 objects / 374872 bytes in 233ms
    01-09 19:07:24.340: D/dalvikvm(293): GC_FOR_MALLOC freed 8497 objects / 649704 bytes in 259ms
    01-09 19:07:25.299: D/dalvikvm(293): GC_FOR_MALLOC freed 6086 objects / 370152 bytes in 293ms
    01-09 19:07:25.969: I/MapActivity(293): Handling network change notification:CONNECTED
    01-09 19:07:25.969: E/MapActivity(293): Couldn't get connection factory client
    01-09 19:07:26.550: D/dalvikvm(293): GC_EXTERNAL_ALLOC freed 3698 objects / 326888 bytes in 303ms
    01-09 19:07:26.990: D/dalvikvm(293): GC_FOR_MALLOC freed 270 objects / 112080 bytes in 220ms
    01-09 19:07:27.299: D/dalvikvm(293): GC_FOR_MALLOC freed 3495 objects / 240288 bytes in 227ms
    01-09 19:07:27.769: D/dalvikvm(293): GC_EXTERNAL_ALLOC freed 185 objects / 136920 bytes in 222ms

エラーがあれば誰かが私に提案できますか?

前もって感謝します

4

1 に答える 1

0

まず、新しい Google API に切り替えます。これは、はるかに使いやすいものです。2 つ目: 簡単な組み込みコマンドを使用して現在の位置を表示できます。本当に古い API を使用する必要がある場合: MyLocationOverview を使用すれば問題ありません:>

于 2013-01-09T13:43:04.600 に答える