【问题标题】:how to create dynamic google map in android如何在android中创建动态谷歌地图
【发布时间】:2011-04-08 14:27:16
【问题描述】:

我检查我的 logcat 文件错误是位置管理为空

公共类 MapsActivity 扩展 MapActivity { 地图视图地图视图; 地图控制器 mc; 地理点 p; 双 latPoint, lngPoint; 位置管理器我的管理器;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mapView = (MapView) findViewById(R.id.mapView);
    LinearLayout zoomLayout = (LinearLayout) findViewById(R.id.zoom);
    View zoomView = mapView.getZoomControls();

    zoomLayout.addView(zoomView, new LinearLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    mapView.displayZoomControls(true);

    mc = mapView.getController();
     LocationManager myManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    myManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,new myLocationListener());

    p = new GeoPoint((int) (latPoint * 1E6), (int) (lngPoint * 1E6));

    mc.animateTo(p);
    mc.setZoom(10);

    //---Add a location marker---

// MapOverlay mapOverlay = new MapOverlay(); // 列表 listOfOverlays = mapView.getOverlays(); // listOfOverlays.clear(); // listOfOverlays.add(mapOverlay);

    mapView.invalidate();

}

@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}

class myLocationListener implements LocationListener {

    public void ListLocationUpdater() {
    }

    @Override
    public void onLocationChanged(Location loc) {
        if (myManager != null) {
            // List list = myManager.getAllProviders();
            String param = (String) myManager.getProviders(true).get(0);
            loc = myManager.getLastKnownLocation(param);
            if (loc != null) {
                latPoint = loc.getLatitude();
                lngPoint = loc.getLongitude();
                Log.e("RootDrawApplication",String.valueOf(latPoint)+"  , "+String.valueOf(lngPoint));

            } else
                Log.e("GoogleMaps ", "Error: Location  is null");
        } else
            Log.e("GoogleMaps ", "Error: Location Manager is null");
    }

    @Override
    public void onProviderDisabled(String provider) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
        // TODO Auto-generated method stub

    }

}

}

【问题讨论】:

    标签: android android-maps


    【解决方案1】:

    您应该设置一个 LocationListener (here)。在 LocationListener 的 onLocationChanged 方法中,只需让您的地图动画到更新的位置即可。

    【讨论】:

    • 我使用 LoationListener 编写代码,但我只显示蓝色背景屏幕,请纠正我。我通过编辑我的问题来粘贴我的新编码。请...
    • 我检查了我的 logcat 文件,错误是位置管理器为空。
    猜你喜欢
    • 2012-06-07
    • 2017-07-27
    • 1970-01-01
    • 1970-01-01
    • 2021-09-27
    • 1970-01-01
    • 1970-01-01
    • 2016-11-27
    • 1970-01-01
    相关资源
    最近更新 更多