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,用起来好多了。第二:您可以通过简单的内置命令显示当前位置。如果你真的必须使用旧的 api:使用 MyLocationOverview 就可以了:>

于 2013-01-09T13:43:04.600 回答