指向我的android地图中的当前位置

时间:2013-01-09 13:23:17

标签: android google-maps

我在我的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

如果有任何错误,有人可以建议我。

提前致谢

1 个答案:

答案 0 :(得分:0)

首先:切换到新的Google API,这是一个 lot 更好用。 第二:您可以通过简单的内置命令显示当前位置。 如果您真的必须使用旧的api:使用MyLocationOverview,你会没事的:&gt;

相关问题