【问题标题】:Pointing current location in my android map在我的 android 地图中指向当前位置
【发布时间】:2012-12-23 13:23:12
【问题描述】:

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

如果有任何错误,谁能给我建议。

提前致谢

【问题讨论】:

  • 设置默认经纬度。
  • 我已经得到了纬度和经度,当它打开时它正在应用程序中烘烤。那么我们真的应该将其设置为默认值吗?

标签: android google-maps


【解决方案1】:

首先:切换到新的 google API,很多 更好用。 第二:您可以通过简单的内置命令显示当前位置。 如果您真的必须使用旧 api:使用 MyLocationOverview 就可以了:>

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-06
  • 2015-11-13
  • 1970-01-01
相关资源
最近更新 更多